help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable for filename in fopen


From: Blitz
Subject: Re: variable for filename in fopen
Date: Mon, 18 Jan 2010 13:59:05 -0800 (PST)

Not sure why you get a parse error, it works just fine for me.  'list'
populates with my file names.  'reading' is the first text file in my
directory (1.txt), so I know this part works.  I am on Octave 3.2.3 under OS
X also.



Carlo de Falco-2 wrote:
> 
> 
> On 18 Jan 2010, at 22:11, Blitz wrote:
> 
>> I need to read a bunch of txt files in a directory.  For some  
>> reason, fopen
>> does not like passing a variable instead of an explicitly declared  
>> string
>> (i.e. "File1.txt").  The snippet below creates an array with file  
>> names,
>> then is supposed to open those files, one by one.  If I replace  
>> 'reading'
>> with some string, it works.  As far as I can tell, the variable  
>> 'reading' is
>> a string, so this should work.  Ideas?
>>
>>
>>
>> list = ls *.txt;
>> for i = 1:length(list),
>>    reading = list(i, :)
>>    fid = fopen(reading, 'r') % open the file
>>    % do stuff
>> end;
> 
> have you actually tried to run this code in Octave? what Octave  
> version are you using?
> on what OS? for me (Octave 3.2.3 on OSX) the first line in your code  
> is invalid and results in a parse error.
> so I don't see how you can say that reading is a string...
> what happens if you run your code and then type just  
> 'reading' (without the quotes) at the octave prompt and press return?
> c.
> 
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

-- 
View this message in context: 
http://old.nabble.com/variable-for-filename-in-fopen-tp27216869p27217477.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]