0

Matlab and textscan issue, sadly. In my case I am able to import my data of interest, using:

f = fopen(file,'r');  % Open text file
data=textscan(f, '%f %f %f %f %f %f %f %f', 'Delimiter',',', 'HeaderLines',14);
fclose(f);

But

In the 12th and 13 rows of the header I have some interesting data, structured as follows:

Calibration Coefficient,0.002501,0.001,0.1294,35.5,200,66.666,1
Offset,0.9,0,0,0,0.7,0,0

so they are strings in the first column, then 7 doubles, that should be coded in this way(?)

param1=textscan(f, '%*s %f %f %f %f %f %f %f','Delimiter',',','HeaderLines',11);
param2=textscan(f, '%*s %f %f %f %f %f %f %f','Delimiter',',','HeaderLines',12);

Actually I was wondering why the param cell is empty, and if was possible to import only the data in rows 12 and 13 of my files.

Thanks in advance.

Aretu
  • 5
  • 3
  • The `textscan` function has a 'count' parameter that you should use for your first lines: Open your file, read line 12 with the correct format, specifying count=1 and header line=11, then read line 13 with count=1, no headerline (if both line have the same format you can read them in one go with count=2). Then read the rest of your file ('count' not specified will read until end of file), then close your file. – Hoki Jun 12 '14 at 21:57
  • Thank you, the help wasn't clear about this counting. However the output cells are empty. Don't know why. – Aretu Jun 13 '14 at 07:10

1 Answers1

0

It looks like you have everything just about right. Here is a minor change that should fix what you need (hopefully)

param1=textscan(f, '%s %f %f %f %f %f %f %f',1,'Delimiter',',','HeaderLines',11);
param2=textscan(f, '%s %f %f %f %f %f %f %f',1,'Delimiter',',','HeaderLines',12);

Notice the insertion of '1' before Delimiter. I'm pretty sure this says to just read 1 set of '%s %f %f %f %f %f %f %f' before stopping. This way you are only reading the 12 and 13th lines and saving them to param1 and param2 respectively. I'm not getting any null cells either.

Hope this helps!

PatchJob
  • 162
  • 2
  • 10
  • Thanks it's very helpful, also for further working with textscan. However, the output cell (param1,2) are empty. Who knows why. Fear that I have some problems with cells. – Aretu Jun 13 '14 at 07:17
  • Hm... how are you accessing the values of param1? If you use curly brackets like param1{2} from the cmd window is the result still empty? – PatchJob Jun 13 '14 at 19:36
  • i found out that the param files are empty because I was playing wrong with the headerlines. The file was opened once for the 3, but the headerlines are meant for the file opened once per command. I checked this stuff and changing the headerlines I was able of picking the correct row and so thanks again. – Aretu Jun 14 '14 at 20:28