[Top][All Lists]

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

Problem with exist()

From: John W. Eaton
Subject: Problem with exist()
Date: Thu, 6 May 2004 14:42:27 -0500

On  6-May-2004, Hamish Allan <address@hidden> 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

Why not just use something like

  function ret = auinf (name)

    ret = auload (file_in_loadpath (sprintf ("%s.wav", name)));



and then call it like this to get the audio_stuff in the top-level

  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.


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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