Read the data from specific line from multiple files.

2 Ansichten (letzte 30 Tage)
Tez
Tez am 16 Jul. 2017
Kommentiert: Tez am 17 Jul. 2017
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 Kommentar
Tez
Tez am 17 Jul. 2017
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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by