Read the data from specific line from multiple files.

조회 수: 1 (최근 30일)
Tez
Tez 2017년 7월 16일
댓글: Tez 2017년 7월 17일
I have sequence of data files(".tab" files), each file with more than 11100 rows and 236 columns. In each file first few lines are headerlines and I have to skip those lines. The data begins from different lines in each file. How can I read only the data values from all the files upto the end of file? Also I have to read some of the variable columns from all the files. How can it be done? I had written a code for it. But it does not work properly. It takes too much time to run the program and the variable values are not taken. I am attaching one of my file here.
{{
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
}
  댓글 수: 1
Tez
Tez 2017년 7월 17일
All the files in the folder are opened. Each file has 236 columns and each column contain both NaN and numerical values.But the variables(eg: n,h) in the columns shows only NaN while running the code. I have to read some of the variable columns (eg: columns 2, 5,197 etc)from each file. What should I do for it?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Pattern Recognition and Classification에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by