Thread Subject: Workspace is empty

Subject: Workspace is empty

From: Jos

Date: 24 Nov, 2009 09:28:05

Message: 1 of 9

Hi,

I am making a GUI that plots all sorts of graphs and more. Untill last week, I had no problems. And if I had one, Workspace was of great benefit to find the problems.
However, this week, for some reason, my Workspace is always empty! I don't think I changed anything that can cause this. Does anyone have an idea about what could have happened? (The only thing I did after last week was to make an executable out of my program using Compiler)

Subject: Workspace is empty

From: Jos

Date: 24 Nov, 2009 09:33:03

Message: 2 of 9

Btw, I'm not using the Compiled version, but work from the real Matlab code.

Subject: Workspace is empty

From: ImageAnalyst

Date: 24 Nov, 2009 12:42:09

Message: 3 of 9

On Nov 24, 4:33 am, "Jos " <jappedane...@mathworks.com> wrote:
> Btw, I'm not using the Compiled version, but work from the real Matlab code.

-------------------------
Is it empty for EVERY m-file you run, or just for that particular one?

What if you have a simple script in an m-file that just says

workspace;
a=magic(5)

Is the workspace still empty after that?

Subject: Workspace is empty

From: Jos

Date: 24 Nov, 2009 12:54:03

Message: 4 of 9

If I run an m-file with eg:
a=12

a is put in the workspace. But if I run any of the functions used by the GUI, they do not go into the workspace. Even if I add a=3 to one of the functions and run it, a is still not overwritten in the workspace and remains equal to 12 :s


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e74725ca-bf13-40e9-888d-4bb076577332@g23g2000vbr.googlegroups.com>...
> On Nov 24, 4:33?am, "Jos " <jappedane...@mathworks.com> wrote:
> > Btw, I'm not using the Compiled version, but work from the real Matlab code.
>
> -------------------------
> Is it empty for EVERY m-file you run, or just for that particular one?
>
> What if you have a simple script in an m-file that just says
>
> workspace;
> a=magic(5)
>
> Is the workspace still empty after that?

Subject: Workspace is empty

From: Jos (10584)

Date: 24 Nov, 2009 13:31:20

Message: 5 of 9

"Jos " <jappedaneels@mathworks.com> wrote in message <hegl1b$j3p$1@fred.mathworks.com>...
> If I run an m-file with eg:
> a=12
>
> a is put in the workspace. But if I run any of the functions used by the GUI, they do not go into the workspace. Even if I add a=3 to one of the functions and run it, a is still not overwritten in the workspace and remains equal to 12 :s
>
>
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e74725ca-bf13-40e9-888d-4bb076577332@g23g2000vbr.googlegroups.com>...
> > On Nov 24, 4:33?am, "Jos " <jappedane...@mathworks.com> wrote:
> > > Btw, I'm not using the Compiled version, but work from the real Matlab code.
> >
> > -------------------------
> > Is it empty for EVERY m-file you run, or just for that particular one?
> >
> > What if you have a simple script in an m-file that just says
> >
> > workspace;
> > a=magic(5)
> >
> > Is the workspace still empty after that?

Should your FUNCTION (not script) return something or create something in the base workspace? In other words, aren't you just pondering over something trivial, namely that functions have their own workspace?

Jos

Subject: Workspace is empty

From: Jos

Date: 24 Nov, 2009 13:55:19

Message: 6 of 9

"Jos (10584) " <#10584@fileexchange.com> wrote in message <hegn78$5ti$1@fred.mathworks.com>...
> "Jos " <jappedaneels@mathworks.com> wrote in message <hegl1b$j3p$1@fred.mathworks.com>...
> > If I run an m-file with eg:
> > a=12
> >
> > a is put in the workspace. But if I run any of the functions used by the GUI, they do not go into the workspace. Even if I add a=3 to one of the functions and run it, a is still not overwritten in the workspace and remains equal to 12 :s
> >
> >
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e74725ca-bf13-40e9-888d-4bb076577332@g23g2000vbr.googlegroups.com>...
> > > On Nov 24, 4:33?am, "Jos " <jappedane...@mathworks.com> wrote:
> > > > Btw, I'm not using the Compiled version, but work from the real Matlab code.
> > >
> > > -------------------------
> > > Is it empty for EVERY m-file you run, or just for that particular one?
> > >
> > > What if you have a simple script in an m-file that just says
> > >
> > > workspace;
> > > a=magic(5)
> > >
> > > Is the workspace still empty after that?
>
> Should your FUNCTION (not script) return something or create something in the base workspace? In other words, aren't you just pondering over something trivial, namely that functions have their own workspace?
>
> Jos

I used the workspave very often to solve errors or problems I couldn't immidiatly solve. So in my opinion, it is not just something trivial. Anyway, I'll try to solve it by just using test-scripts which do not run in seperate functions (and are not controlled by the GUI) in order to see everything in the workspace.

Subject: Workspace is empty

From: ImageAnalyst

Date: 24 Nov, 2009 14:03:56

Message: 7 of 9

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 but I don't think so because
if you do something like

function test(0
global a;
a=12;
return;

once you run the function and it exits, the variable a is not seen in
the base workspace - so I think the global workspace is different than
the base workspace. Besides if you put
b=evalin('base', 'a');
inside the function, it gives an error saying "a" is undefined, so
again it looks like the global workspace is different than the "base"
workspace.

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).
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).

Anyway, that's my understanding of it.

Subject: Workspace is empty

From: Jos

Date: 24 Nov, 2009 14:35:17

Message: 8 of 9

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <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 but I don't think so because
> if you do something like
>
> function test(0
> global a;
> a=12;
> return;
>
> once you run the function and it exits, the variable a is not seen in
> the base workspace - so I think the global workspace is different than
> the base workspace. Besides if you put
> b=evalin('base', 'a');
> inside the function, it gives an error saying "a" is undefined, so
> again it looks like the global workspace is different than the "base"
> workspace.
>
> 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).
> 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).
>
> Anyway, that's my understanding of it.

Okay, thanks for the explanation. I'll just contiue working without the usefull help of the workspace :)

Subject: Workspace is empty

From: Steven Lord

Date: 26 Nov, 2009 23:42:52

Message: 9 of 9


"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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com