|
"ImageAnalyst" <imageanalyst@mailinator.com> wrote in message
news:d0d84ffe-8d3c-416b-bd82-b24d4794a648@u20g2000vbq.googlegroups.com...
> Functions have their own workspace that is separate from the global
> "base" workspace. When you're in the function, say stopped at a
> breakpoint, you can see only the function's workspace. You can see
> other variables in the "global" workspace if you declare the variable
> global in the function. I'm a little fuzzy if declaring variables
> global puts them into the base workspace
No, the global workspace is a separate workspace from the base workspace.
[And luckily, GLOBAL is a keyword so you can't create a function global.m
and stop inside its workspace, because that would be a different global
workspace :]
*snip*
> So, in summary, each function has it's own workspace, and you don't
> see the base workspace in the workspace panel when you are in a
> function (either just runnig it, or stopped at a breakpoint).
The reverse is true; when you're in the base workspace (usually because
you're not running a function, but you can also change to the base workspace
while debugging using DBUP and DBDOWN) you can't "see" anything in a
function workspace if one exists.
> Functions can share variables through the use of the "global" keyword,
> but those variables are in some special global workspace, not the main
> "base" workspace of MATLAB. Functions can see ONLY those global
> variables that are declared global in the function, not ALL of them by
> default. In other words, you pick the global variables that you want
> to see (you can pick all of them if you want but you have to do it
> name by name I think).
Depending on what you want to know about the global variables, "S =
whos('global')" may give you the information you want.
> Anyway, that's my understanding of it.
To add to ImageAnalyst's explanation, what I think you want to do is either
to use the Workspace window to debug your function (in which case you can
set a breakpoint in your function -- when MATLAB reaches that breakpoint,
you will be in the function workspace and so can see the variables in that
workspace) or you want to have access to some of the variables in the
function workspace after it exits, in which case you need to get those
variables into the base workspace.) The most common way to do the latter is
to return those variables from the function as output arguments, although
there are others.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|