0

I have a '.ismr' file which I am able to open with fopen. The file has several columns (but I am interested in first 9 of them) and several rows. On of the rows is:

1655, 60.00, 12, 00A00000, 184.25, 21.92, 42.02, 0.099385, 0.079280,

After opening the file, I am using tline to read one line at a time and then using textscan as follows:

xyz = textscan(tline,'%f, %f, %f, %s %f, %f, %f, %f, %f,');

When I run my script, it only gives me first three readings from the row correctly (i.e. 1655,60.00 and 12) but from 4th onwards, I am not getting anything or just garbage.

Please help me to correct my script. Thanks

Mushi
  • 367
  • 2
  • 4
  • 14

1 Answers1

1

Why not just use comma as your delimiter, rather than putting it into the format?

xyz = textscan(tline,'%f%f%f%s%f%f%f%f%f','Delimiter',',');

Note that you can use textscan directly on the file to read multiple rows with the same format, you don't need to read the line in before processing it.

nkjt
  • 7,825
  • 9
  • 22
  • 28
  • This is what I am getting (bunch of 3 values as one): [1655;0.0662170000000000;115.224609000000] [60;0.0712130000000000;0.274199000000000] [12;0.0761330000000000;115.127876000000] <3x1 cell> [184.250000000000;0.0764090000000000;115.347588000000] [21.9200000000000;-29.9933040000000;0.276983000000000] [42.0200000000000;0.0490000000000000;17544.8700000000] [0.0993850000000000;115.338326000000;8109] [0.0792800000000000;-0.0549600000000000] – Mushi Jun 19 '14 at 11:07
  • Also, please tell me how can limit text scan to read only first 9 columns and ignore the rest. – Mushi Jun 19 '14 at 11:23
  • Edit your question to give more info about your format. `textscan` will automatically read multiple rows if it can so it looks like it's reading three in (the 3x cell will have three strings in) and collecting them by columns. For the other, look at the `textscan` help section labelled "Skip the Remainder of a Line" – nkjt Jun 19 '14 at 13:10
  • When I am opening the file, it appears as the same as I posted in my question. I don't know what should I explain further about the format of the file. Anyway, thanks for the skipping part. – Mushi Jun 19 '14 at 13:37
  • You've shown one row. If all the rows are the same, then fine. If some of the rows are different, that's an isuse. – nkjt Jun 19 '14 at 13:47