help-octave
[Top][All Lists]
Advanced

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

Problem with exist()


From: Hamish Allan
Subject: Problem with exist()
Date: Thu, 6 May 2004 20:13:09 +0100

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;

# more stuff here
----

Calling this from the command line has the desired effect:

----
octave:1> auinf('xyz');
xyz_pcm = auload(file_in_loadpath("xyz.wav"));
octave:2> whos -v

*** local user variables:

prot  type                       rows   cols  name
====  ====                       ====   ====  ====
 rwd  matrix                    44100      2  xyz_pcm

octave:3>
----

BUT, when I call it again, it loads the data again:

----
octave:3> auinf('xyz');
xyz_pcm = auload(file_in_loadpath("xyz.wav"));
octave:4>
----

Calling exist() from the command line does what you would expect:

----
octave:4> !exist('xyz_pcm')
ans = 0
octave:5>

But it seems that the exist() within the function returns a different value. Can someone explain this to me?

Thanks,
Hamish



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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