Re: problems with persistence
- From: Peter Boettcher <boettcher@xxxxxxxxxx>
- Date: Wed, 30 Apr 2008 09:37:26 -0400
REIDAR <aureid@xxxxxxxxx> writes:
To put it simply, my persistent variables aren't persisting (between
function calls)
I've attached my code, but I'll describe what is going wrong. When I
start up my program, I tell the function to 'clear'. This clears all
the values, and reinitializes everybody. Later on, when I try to
store a value, it doesn't have the variables in memory, so it
reinitializes them, wiping out the structure, and leading to a whole
pantload of error messages.
I understood that the whole point of persistant variables is that they
persist. What am I doing wrong?
My code has a little method for storing everything, it looks like
this:
function out=database(direction,name,value)
switch direction
case 'clear'
out=-1;
clear stacks names index
persistent stacks names index
stacks=struct('matrix',[]);
names=struct('string',[]);
index=0;
case 'return'
switch name
case 'stacks'
out=stacks;
return
Since persistent is in the 'clear' case, the 'return' case does not know
that the variables are supposed to be persistent.
Instead, put the "persistent" line at the top, before the "switch"
block. And there's no need to clear the variables for initialization.
Just directly set them to the initial values.
-Peter
.
- Follow-Ups:
- Re: problems with persistence
- From: REIDAR
- Re: problems with persistence
- References:
- problems with persistence
- From: REIDAR
- problems with persistence
- Prev by Date: inverse Helmholtz solver
- Next by Date: Re: problems with persistence
- Previous by thread: problems with persistence
- Next by thread: Re: problems with persistence
- Index(es):
Relevant Pages
|