help-octave
[Top][All Lists]
Advanced

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

Re: load command question


From: Bill Denney
Subject: Re: load command question
Date: Sun, 7 May 2006 22:31:53 -0400 (EDT)

On Mon, 8 May 2006, Stefan van der Walt wrote:

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

which will execute

load(myfile1.dat)

I think you were meaning eval instead of exec, and you can't contatenate strings and numbers like that-- you need something like num2str. Also, a simpler, safer, and probably faster way to do this would be to do this:

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

It's simpler because you don't have as much indirection. It's safer because you don't have to worry (or at least worry as much) about what characters are in the filename (what if you accidentally put a | in there). I think it's faster because I think that eval is a relatively slow call.

Bill

--
"Only a life lived for others is worth living." -- Albert Einstein



reply via email to

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