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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

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));
 end

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

why.?

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

0 Comments

Lalit Patil

Products

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');
fclose(fid)

0 Comments

Walter Roberson

Contact us