Extracting data from multiple files with header.

I have a program for extracting numeric data from single text file, but I don't know how to use for loop for extracting numeric data from multiple files at one go. This data seperated by space. Below is my code for single <file:->
clear all
numFiles = 1302;
startRow = 44;
endRow = inf;
myData = cell(1,numFiles);
for fileNum = 1:numFiles
fid = fopen('20030215401v0200s.n2o', 'rt');
Data = textscan(fid, '%f %f %f %f %f', 'headerLines', 43, 'CollectOutput', true);
fclose(fid);
Data= cell2mat( Data);
end

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 6 de Jul. de 2015
Editada: Azzi Abdelmalek el 6 de Jul. de 2015
f=dir(fullfile(YourFolder,'*.txt'));
files={f.name}
for k= 1:numel(files)
fid = fopen(fullfile(YourFolder,files{k}), 'rt');
Data = textscan(fid, '%f %f %f %f %f', 'headerLines', 43, 'CollectOutput', true);
Data= cell2mat( Data);
out{k}=Data;
fclose(fid);
end

1 comentario

Parul Tandon
Parul Tandon el 6 de Jul. de 2015
Hi,thankyou for your code,I ran the code,but it gave me the following result.
>> Trial1 >> Trial1 f = 0x1 struct array with fields: name date bytes isdir datenum files = {}

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 6 de Jul. de 2015

Comentada:

el 6 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by