How does one input a large amount of data that has a different number of columns per row?

Hi, I am trying to load in a few thousand files using textscan that are in the following format:
3245
0,1,2,3,4,......500
0.23,0.35,0.41,0.57,1.32
0.10,0.83,0.92,1.45
0.66,0.94,1.75,2.35,2.51,3.90
0.13,0.71
I only want to load starting at the 3rd row (i.e. at 0.23). However, starting at the third row, there are actually 500 more rows and a variable number of columns (on the order of a few hundred). (I don't need to load in the first two lines). But I can't figure out how to do this. I can't input them row by row, because there are 500 of them, and a few thousand files. I want to be able to access each number separately of course (say data(2,3)=0.92), and to fill in the extra spaces with NaN or something. Can someone please help me with this?
Kyla

 Respuesta aceptada

per isakson
per isakson el 22 de Sept. de 2012
Editada: per isakson el 23 de Sept. de 2012
textscan cannot parse rows with variable number of columns. AFAIK: there is no function in Matlab that can do that.
There are many approaches to read the file. Two of them:
  1. one line at a time with fgetl
  2. read each line as a string with textscan and parse in a second step
.
--- textscan CAN parse rows with variable number of columns ---
I was wrong. This code parses the first NCOL columns, where NCOL is the number of columns of the shortest row.
fid = fopen('h:\m\cssm\ascii_with_variable_row_length.txt');
cac = textscan( fid, '%f%f%*[^\n]', 'CollectOutput', true );
fclose( fid );
cac{1}
prints
ans =
17 24
23 5
4 6
10 12
11 18
where 'h:\m\cssm\ascii_with_variable_row_length.txt' contains
17 24 1 8 15
23 5 7
4 6 13 20 22
10 12
11 18 25 2 9

2 comentarios

OK, thank you for letting me know!
Sorry, now I know better! See above.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Sept. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by