|
From: | Carlo de Falco |
Subject: | Re: variable for filename in fopen |
Date: | Mon, 18 Jan 2010 22:31:42 +0100 |
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' isa 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.
[Prev in Thread] | Current Thread | [Next in Thread] |