Combining large text files of different sizes

7 visualizaciones (últimos 30 días)
Todd Gilbert
Todd Gilbert el 30 de En. de 2015
Comentada: dpb el 18 de Feb. de 2015
I have two large text files containing data that I want to load into MATLAB and place into a single matrix (:,3)
  • The files are different sizes, but each contain time values in the first column.
  • The files contain some superfluous header information on the first few rows, that I will need to comb out
  • The time data is formatted differently in each file, so I will need to reformat using one scheme.
  • I want to merge them, so I end up with three columns: time, data1 and data2; with the time elements blended to create one sorted time column with appropriately aligned/coordinated data
What is the most-efficient method?
  3 comentarios
Todd Gilbert
Todd Gilbert el 17 de Feb. de 2015
Will you please add some granularity/detail to your explanation?
dpb
dpb el 18 de Feb. de 2015
What's to say?
Open and read the two files independently...
fid=fopen('file1');
d1=textscan(fid,fmt1,'headerlines',N,'collectoutput',1);
fid=fclose(fid);
fid=fopen('file2');
d2=textscan(fid,fmt2,'headerlines',M,'collectoutput',1);
fid=fclose(fid);
Convert the time columns to datenums and sort; keep the order index for the other data to go with revised order...
[dn,idx=sort[datenum(d1{1},'properformat');
datenum(d2{1},'properformat')]);
Convert the other cell to array; concatenate and rearrange into single array
d=[cell2mat(d1{2});dn2 cell2mat(d2{2})];
d=[dn d(idx)];
You'll have to fixup the formatting differences, number of headerlines, etc., etc., etc., of which you gave no details...

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by