从MATLAB中的多个文件中读取特定行的数据

时间:2017-07-16 14:23:37

标签: matlab multiple-files

我有一系列数据文件(“。tab”文件),每个文件包含超过11100行和236列。在每个文件中,前几行是标题,我必须跳过这些行。数据从每个文件中的不同行开始。如何只读取文件末尾的所有文件中的数据值?另外,我必须阅读所有文件中的一些变量列。怎么做到呢?我为它写了一个代码。但它不能正常工作。运行程序需要太多时间,并且不会采用变量值。 可以帮我修改代码和读取数据吗?

clear all;
clc;
files=dir(fullfile('C:\Users\Documents\MATLAB\2015\02\*.tab'));
for i=1:28
  fid(i)=fopen(files(i).name);
  files(i).values=textscan(fid(i), '%s','delimiter','','HeaderLines',296,'MultipleDelimsAsOne',1);
formatSpec='%19s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%16s%s%[^\n\r]';
  dataArray = textscan(files(i).name,formatSpec, 'Delimiter', '', 'WhiteSpace', '',  'ReturnOnError', false);
  raw = repmat({''},length(dataArray{1}),length(dataArray)-1);
  for k=1:11900;l=1:236;
      raw(k,l) = raw(length(dataArray{1}),length(dataArray)-1);
      n = str2double(raw(:, 2));
      h = str2double(raw(:, 197));
  end
      fclose('all');
end

0 个答案:

没有答案