0
votes

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.

1
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
Thank you, the help wasn't clear about this counting. However the output cells are empty. Don't know why. - Aretu

1 Answers

0
votes

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!