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

New to MATLAB?

code shows error in function

Asked by Lalit Patil

Lalit Patil

on 21 Dec 2012
Accepted Answer by Walter Roberson

Walter Roberson

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

Lalit Patil

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson

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

Walter Roberson

Contact us