Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

fscanf to read a file which contains an intensity image

Asked by Alexandre on 8 Dec 2012

Hello, I need to read a file that contains an double/float matrix in format

1,    1,   0.00,   0.00,   0.00,      2426 
(.....) 
248,  256,   0.00,   0.00,   0.00,      1839                                 
  

problem is that in the first 142 lines, there are strings which i have to ignore, and I'm not getting fscanf to work. Im not allowed to use textscan This is how im calling fscanf:

A = fscanf(fid, '%f %f %f %f %f %f', [6, inf])

In help fscanf, it says that the lines that arent in the specified format will be ignored, but that doesn't happen

Reply please, thank you!

1 Comment

Jan Simon on 8 Dec 2012

What is the question we could reply to?

Alexandre

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson on 8 Dec 2012

Where do you see that in the help for fscanf? The documentation says,

   If fscanf cannot match the format to the data, it reads only the portion that matches into A and stops processing.

0 Comments

Walter Roberson
Answer by Jan Simon on 8 Dec 2012

How to skip 142 lines:

fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file: %s', FileName); end
for k = 1:142
  fgets(fid);
end

0 Comments

Jan Simon

Contact us