[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need help setting a flag once in sub.m when called from main.m
From: |
Jaroslav Hajek |
Subject: |
Re: Need help setting a flag once in sub.m when called from main.m |
Date: |
Tue, 9 Mar 2010 21:09:15 +0100 |
On Tue, Mar 9, 2010 at 3:47 PM, Svante Signell <address@hidden> wrote:
> On Tue, 2010-03-09 at 12:05 +0100, Jaroslav Hajek wrote:
>> On Tue, Mar 9, 2010 at 11:52 AM, Svante Signell
>> <address@hidden> wrote:
>> > On Tue, 2010-03-09 at 10:06 +0100, Jaroslav Hajek wrote:
> ..
>> >
>> > Sorry, setting persistent in the calling script does not work. From my
>> > understanding it can only be used in a function.
>> >
>>
>> You wrote "from the main function", not "main script".
>
> Sorry, a typo from me.
>
> ..
>> Persistent variables are the nice way to do this. If you want to avoid
>> the explicit checking, you can do (this is in fact what I suggested
>> before);
>>
>> sub.m:
>> function status = sub ()
>> persistent status = sub1 ();
>> endfunction
>> function status = sub1 ()
>> printf ('sub1.m: Entering here once\n');
>> status = 'yes';
>> endfunction
>>
>> If you want something really hacky-wacky,
>>
>> function status = sub ()
>> printf ('sub.m: Entering here once\n');
>> status = 'yes';
>> assignin ("caller", "sub", status);
>> endfunction
>>
>> but don't let this code anywhere near me :)
>
> Thanks for your help. My problem is that I'm converting some .m code
> to .mex code and things easily get hairy, whatever you do, especially
> with persistent variables. Working with the mex interface is
> non-trivial :-(
>
I know, that's why I almost never use it. The C++ interface of Octave
is both more convenient and more powerful.
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz