Read specific line in Matlab

1 view (last 30 days)
Anders Bennedsgaard
Anders Bennedsgaard on 5 Oct 2015
I have a textfile with some data, which i've made in MatLab with the fwrite-command. Only, now i've discovered i need to use those data again, and i'm not entirely sure how to import it again, and only read one specific line. I've found some commands to do this like 'fileread', but i'm not sure how to use it. My textfile i'm trying to import again, is something looking like this:
General model:
VA1(x) = a*x+b
Coefficients (with 95% confidence bounds):
a = -0.0191 (-0.04125, 0.003042)
b = 0.2261 (0.2056, 0.2466)
I'm trying to get the values for a, in again.
As a sidenote: This data is called '2_1speed.txt', but when i'm trying to import this using 'fopen', it shows an error, because of the underscore. Is there a way to still import it, with the underscore in the name of the file?

Answers (1)

Steven Lord
Steven Lord on 5 Oct 2015
Rather than writing the fit object's displayed text to a text file, next time consider saving the object itself to a MAT-file. Then you could use COEFFVALUES on that object to retrieve the full precision value of that parameter, rather than the truncated version included in the displayed text.
FOPEN should be able to handle files with underscores in the name. Call FOPEN with two outputs and check the second output to see what it says is the problem with opening that file.
  1 Comment
Anders Bennedsgaard
Anders Bennedsgaard on 5 Oct 2015
Yeeah, i kinda figured that out by now.. But it was just a quickly made script..
Also, i've tried to use the excact same file called 21speed.txt, and that one worked fine. I've read that numbers and underscores cant be the first thing in the name, but when i removed the underscore, it worked like a charm.. I've got over 500 data-sets..

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!