MATLAB Answers


code shows error in function

Asked by Lalit Patil on 21 Dec 2012

I am using following code to write text file.. This is the part of a function.. and it works...

 fid = fopen(sprintf('Image%d.txt',imageNumber),'wt');
 for j=1:length(y),
    fprintf(fid,'%f %f\n',y(j),x(j));

Now when i am using following code to read the same file then it shows error..


 C = textscan('Image%d.txt',imageNumber);



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 21 Dec 2012
 Accepted answer

You do not textscan() a file name: you textscan() a file identifier created by fopen()

fid = fopen(sprintf('Image%d.txt',imageNumber),'rt');
C = textscan(fid, '%f%f');


Join the 15-year community celebration.

Play games and win prizes!

Learn more
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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!