fopen function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

fopen function

taquito
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: fopen function

Doug Stewart-4


On Fri, Dec 20, 2019 at 6:56 PM taquito <[hidden email]> wrote:
Hi! I'm trying to open a text file with fopen. The name of the file is '352'.
If I do this

fid=fopen('352', 'rt');
formato=('%s %s %s %s %s %s %s %s');
data = textscan(fid,formato,'HeaderLines',9);
fclose(fid);

fid>1 then everything is Ok. But if I define the variables a=1, b=351, and
c=a+b, then:

a=1;
b=351;
c=a+b;

fid=fopen('c', 'rt');
formato=('%s %s %s %s %s %s %s %s');
data = textscan(fid,formato,'HeaderLines',9);
fclose(fid);

then fid=-1 and the file hasn't opened. Do you know why happen this, and how
can I solve it? Thanks!


the first 352 is a string and the second 352 is a number.
Try using the mat2str function


a=1;
b=351;
c=a+b;
sc=mat2str(c)
fid=fopen(sc, 'rt');
formato=('%s %s %s %s %s %s %s %s');
data = textscan(fid,formato,'HeaderLines',9);
fclose(fid);


I did not try this but I think it should work

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: fopen function

taquito
Thanks Doug, but it didn't work neither.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: fopen function

taquito