help-octave
[Top][All Lists]
Advanced

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

Re: load command question


From: Quentin Spencer
Subject: Re: load command question
Date: Sun, 07 May 2006 21:25:33 -0500
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Stefan van der Walt wrote:

On Sun, May 07, 2006 at 07:04:43PM -0500, Quentin Spencer wrote:
Myriam Abramson wrote:

How do I load a file with a variable name?


octave> mypattern
mypattern = random4.out
octave> mypattern
mypattern = random4.out
octave> load mypattern
error: load: couldn't open input file `mypattern'
octave> load "mypattern"
error: load: couldn't open input file `mypattern'
octave>

A useful trick is to build command lines from strings.  For example,
if you have

x = "1"
filename = "myfile"

you can do

exec(["load(", filename, x, ".dat)"])

which will execute

load(myfile1.dat)

You can also do things like this with sprintf, which I think gives even more flexibility:

x="1";
filename="myfile";
load(sprintf("%s%s.dat",filename,x));

or

x=1;
filename="myfile";
load(sprintf("%s%i.dat",filename,x));



Quentin


reply via email to

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