首页 > 解决方案 > 读取带有标题的文件并提取数据

问题描述

我正在尝试从文件中提取数据。该文件包含 37 列,每列都有一个标题。我似乎不能只提取数据。我不确定要使用什么功能。最终我需要执行一些计算,然后输出更多数据。

我尝试过使用 dlmread、textscan、load 和其他一些。我不太了解这些函数如何与不同类型交互。我已经仔细检查了我正在打开正确的文件并且文件中填充了值。

% Prompt user to select the folder containing the data
testfolder = uigetdir();

datastore = zeros (0,37); 


for i= 1:2

   subfoldertxt = [testfolder, '\t.txt'];

   %datastore = dlmread(subfoldertxt,',');

    store = textscan(subfoldertxt,'%s','delimiter',',', 'HeaderLines', 37 
);
datastore = textscan(subfoldertxt,'%f', 'delimiter','\t');

 %There are 37 columns. 18 are used as pairs, one column (the 15th) is left 
over.  
for column = 1:18

   if column < 15
Error(:,column)=datastore(:,column) - datastore (:, column + 18);
   elseif column >15
Error(:,column)= datastore(:,column) -datastore(:, column + 19);
   end
end

我希望数据存储保存文件中的值,以便可以计算错误。目前我得到一个完全为空的 1x1 单元阵列。

标签: matlabfile-io

解决方案


推荐阅读