help-octave
[Top][All Lists]
Advanced

[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: Svante Signell
Subject: Re: Need help setting a flag once in sub.m when called from main.m
Date: Tue, 09 Mar 2010 15:47:07 +0100

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





reply via email to

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