large text file reading
Mostrar comentarios más antiguos
Hello,
I am currently working on a program that will read a large text file and then export it into an excel file in a different organization. My file i am trying to read contains information in this form...
Time Pz Fz Fy My Ra Fx
0.000 12.350 1062.0 -9.9 12.0 245.391 0.8
0.040 12.348 1062.3 -9.2 10.3 245.391 0.8
0.080 12.347 1062.7 -9.6 5.2 245.391 1.1
0.120 12.347 1062.3 -9.6 5.2 245.391 0.7
0.160 12.347 1061.6 -9.9 13.8 245.391 0.2
0.200 12.349 1061.6 -9.6 -5.2 245.391 -0.3
0.240 12.350 1061.6 -9.9 -1.7 245.391 -0.1
0.280 12.350 1062.0 -9.9 10.3 245.391 0.4
0.320 12.348 1062.3 -9.2 18.9 245.391 0.6
0.360 12.347 1062.7 -9.4 15.5 245.391 0.8
and then it repeats 4 times going down the page. what is the best way for me to make my program check for a new title line and then start reading again so that i can end up with 4 matrices full if this data.
Respuesta aceptada
Más respuestas (1)
Ahmed A. Selman
el 26 de Mzo. de 2013
Editada: Ahmed A. Selman
el 26 de Mzo. de 2013
Try this and note to specify your filename input (FIN) and filename output (FOUT) properly, i.e., FOUT must be with extension (xls) or (xlsx), e.g., 1.xls
Filenm =input('Input your FIN File name : ','s'); % here input the filename FIN
file1=fopen (Filenm,'r');
FOUT=input('Input your FOUT File name : ','s'); % here input the filename FOUT
[Binp, dn1]=fscanf(file1,'%s', [7 1]); % here is the header only as a matrix
[Ainp,dn]=fscanf(file1,'%g', [7 inf]); % here is the rest (numeric) values. You have 7 cols so pay attention to change it otherwise.
[doesItWork,TheWarning]=xlswrite(FOUT,Ainp');
if doesItWork==1;
disp ('Passed-- FIN was read and FOUT was written.')
else
TheWarning
end
fclose(file1);
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!