For Programmers: Free Programming Magazines  


Home > Archive > Matlab > May 2005 > global scope









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author global scope
ross

2005-05-29, 8:58 pm

Matlab globals are normally accessible from the command line and all functions.

Is it possible to stay in the interactive environment (ie, m files), but
restrict the scope of globals to the functions within a file, so they are not
accessible from the base workspace?

thanks

ross

per isakson

2005-05-29, 8:58 pm

ross wrote:
>
>
> Matlab globals are normally accessible from the command line and
> all functions.
>
> Is it possible to stay in the interactive environment (ie, m
> files), but
> restrict the scope of globals to the functions within a file, so
> they are not
> accessible from the base workspace?
>
> thanks
>
> ross


No but, nested function "share" by reference the variables defined in
the outer function. See "Scott and Doug's Pick of the W", <http://www.mathworks.com/matlabcentral/pick/>

/ per
metiche

2005-05-29, 8:58 pm

"Is it possible to stay in the interactive environment (ie, m files),
but
restrict the scope of globals to the functions within a file, so they
are not
accessible from the base workspace? "

Try declaring the variables 'persistent' in the file with the
functions.

Bob

2005-05-30, 8:59 pm

"metiche" <ayduda@usa.com> wrote:

>Try declaring the variables 'persistent' in the file with the
>functions.
>
>Bob


Should that work in R13? I can't seem to get it to work ... maybe I'm just
dim. Documentation doesn't mention that use of 'persistent' as far as I can
see.

ross


Loren Shure

2005-05-31, 4:05 pm

In article <d7fstu$7r2$1@arachne.labyrinth.net.au>, ross@nospam.com
says...
> "metiche" <ayduda@usa.com> wrote:
>
>
> Should that work in R13? I can't seem to get it to work ... maybe I'm just
> dim. Documentation doesn't mention that use of 'persistent' as far as I can
> see.
>
> ross
>
>
>


persistent is a part of the R13 language. It's scope is on a function
basis -- not by file.

--Loren
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com