From help-request at octave dot org Thu May 6 14:42:34 2004 Subject: Problem with exist() From: "John W. Eaton" To: Hamish Allan Cc: help at octave dot org Date: Thu, 6 May 2004 14:42:27 -0500 On 6-May-2004, Hamish Allan wrote: | Hi, | | I'm new to Octave (and Matlab) and I'm trying to use it to do some | audio processing. | | As I'm developing, I'm processing various data in several stages and | visualising some of it. Much of the processing needs only to be done | once. For instance, once I've loaded some PCM data I don't need to | reload it, and when I've created a spectogram of that data I don't | usually need to change it, but if I decide to load different PCM data I | want my spectogram changed, etc. | | I wrote some straightforward code to try to achieve this: | | ---- | function ret = auinf(name) | | pcmname = [name, '_pcm']; | if !exist(pcmname), | cmdname = ["file_in_loadpath(\"" name, ".wav\")"]; | cmdname = [pcmname, " = auload(", cmdname, ");"]; | disp(cmdname); fflush(stdout); | evalin('caller', cmdname); | endif; I'm not sure that I would call anything that uses evalin to be straightforward. Why not just use something like function ret = auinf (name) ret = auload (file_in_loadpath (sprintf ("%s.wav", name))); ... endfunction and then call it like this to get the audio_stuff in the top-level workspace: xyz_pcm = auinf ("xyz"); ? Then just don't call it again for the same argument name unless you want to reload the file. | BUT, when I call it again, it loads the data again: That's because you are evaluating the command that makes the variable name xyz_pcm in the workspace of the caller. The variable xyz_pcm never exists in the workspace of your auinf function. jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------