how to read mutliple text files

4 vues (au cours des 30 derniers jours)
Raju Mandapti
Raju Mandapti le 3 Juil 2011
hi i am very new to matlab. i wanted to read multiple text files. who files names have increment in number such data1112, data1113... 4096 files..
i have single text file read program...
filename='data1112.txt' fid=fopen(filename, 'r') tline=fgetl(fid) [a,b]=strtok(tline, '=') [c,d]=strtok(b, '=') cnum=str2num(c) fclose(fid)
Pls mention how to use for loop and i wanted to extract all data in one matrix form..
Thanks in advanced

Réponses (1)

Paulo Silva
Paulo Silva le 3 Juil 2011
data=cell(4096-1112,1);
for n=1112:4096
filename=['data' num2str(n) '.txt']
%insert the code to get data from the file
a=rand;b=rand; %this is my fake data
c=rand;d=rand; %more fake data
data{n-1111}={a,b,c,d}; %each cell is the data for each file
%I have no idea about the size or type of a,b,c,d so I used cells again
end
  1 commentaire
Raju Mandapti
Raju Mandapti le 3 Juil 2011
hi Paulo Silva
thanks a lot...Its working nicely...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Text Data Preparation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by