Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How can I create my own workspace?

Subject: How can I create my own workspace?

From: Husam Aldahiyat

Date: 12 Mar, 2010 21:23:05

Message: 1 of 11

Hello,
What I mean is, how can I transfer the workspace and all its variables (including loop counters and toc) from a nested function, for example, and make it available in another function?

Subject: How can I create my own workspace?

From: Walter Roberson

Date: 12 Mar, 2010 21:40:09

Message: 2 of 11

Husam Aldahiyat wrote:

> What I mean is, how can I transfer the workspace and all its variables
> (including loop counters and toc) from a nested function, for example,
> and make it available in another function?

Do you need only read access, or read/write access?

Is it acceptable to have one or more "accessor" functions that need to be
called to get or set the values, or is your expectation that the workspace
will be "shared" and that you will be able to access the variables by name,
something along the lines of:

%FizzBoom is a variable in the nested function

import_the_workspace();

%display what FizzBoom is currently in the nested function without
%specifically importing it
disp(FizzBoom);

pause(0.5);
%display the updated FizzBoom from the nested function without
%specifically asking for it again

disp(FizzBoom);

%if FizzBoom is a loop counter of an active loop, then if you update its
%value, is it important that the loop skip (or go back) to the new value?
%Keeping in mind that if you try to assign a new value to a loop counter from
%within matlab, that at the beginning of the next loop trip the change in
%value would be ignored and the next loop value in normal sequence would be
%used -- so do you need access to the *internal* variables to be able to
%mess with them?

FizzBoom = FizzBoom + 23;


You will likely not be able to access the toc() value: the start time is saved
by tic to an unnamed location.

Subject: How can I create my own workspace?

From: Matt J

Date: 12 Mar, 2010 22:02:05

Message: 3 of 11

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <hnebbp$eof$1@fred.mathworks.com>...
> Hello,
> What I mean is, how can I transfer the workspace and all its variables (including loop counters and toc) from a nested function, for example, and make it available in another function?
=================

You can return a function handle fhandle to the nested function. Then, if I've understood what you're after, you can use the function below.

function StateStruct=wspace(fhandle)
%Get the workspace of a function handle
%
% StateStruct=wspace(fhandle)
%
%For now, very rudimentary.


z=functions(fhandle);
StateStruct=z.workspace{1};

Subject: How can I create my own workspace?

From: jojo

Date: 12 Mar, 2010 22:40:45

Message: 4 of 11

i bet you have a big ''youknow


---
frmsrcurl: http://compgroups.net/comp.soft-sys.matlab/How-can-I-create-my-own-workspace

Subject: How can I create my own workspace?

From: Husam Aldahiyat

Date: 12 Mar, 2010 22:58:02

Message: 5 of 11

I don't want to edit the loop counter, and toc isn't very important actually, but I want to obtain which variables were used and make new variables with the exact same name in my new workspace/function, which have the same values as the previous variables. Also, this needs to be general (no passing on information from one function to another).

I think I'm aiming too high but maybe there's something out there?

So far my only option is using image processing and some long techniques to read the workspace window and the values inside.

Subject: How can I create my own workspace?

From: Matt J

Date: 12 Mar, 2010 23:08:02

Message: 6 of 11

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <hnegtq$js1$1@fred.mathworks.com>...

> I think I'm aiming too high but maybe there's something out there?
>
> So far my only option is using image processing and some long techniques to read the workspace window and the values inside.
=====================

Doesn't my proposal accomplish what you've described?

Subject: How can I create my own workspace?

From: Husam Aldahiyat

Date: 12 Mar, 2010 23:30:08

Message: 7 of 11

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hnehgi$13q$1@fred.mathworks.com>...
> "Husam Aldahiyat" <numandina@gmail.com> wrote in message <hnegtq$js1$1@fred.mathworks.com>...
>
> > I think I'm aiming too high but maybe there's something out there?
> >
> > So far my only option is using image processing and some long techniques to read the workspace window and the values inside.
> =====================
>
> Doesn't my proposal accomplish what you've described?

Thank you for the suggestion!
I will try to play around with your
proposal, thanks a lot!

Subject: How can I create my own workspace?

From: Husam Aldahiyat

Date: 13 Mar, 2010 07:09:07

Message: 8 of 11

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <hneiq0$kb9$1@fred.mathworks.com>...
> "Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hnehgi$13q$1@fred.mathworks.com>...
> > "Husam Aldahiyat" <numandina@gmail.com> wrote in message <hnegtq$js1$1@fred.mathworks.com>...
> >
> > > I think I'm aiming too high but maybe there's something out there?
> > >
> > > So far my only option is using image processing and some long techniques to read the workspace window and the values inside.
> > =====================
> >
> > Doesn't my proposal accomplish what you've described?
>
> Thank you for the suggestion!
> I will try to play around with your
> proposal, thanks a lot!

It doesn't work outside nested functions.

function fun1

a = 5;

end

>> z = functions(@fun1)

z =

    function: 'fun1'
        type: 'simple'
        file: 'E:\D N\MATLAB2\MATLAB\goggo\fun1.m'

% There's no workspace field, why? :(

Subject: How can I create my own workspace?

From: Matt J

Date: 13 Mar, 2010 14:10:05

Message: 9 of 11

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <hnfdmj$3q6$1@fred.mathworks.com>...

> It doesn't work outside nested functions.
> % There's no workspace field, why? :(

Because only nested functions allow externally scoped workspace variables. Since you scoped the problem to nested functions only in your original post, I obviously focused only on that.

Subject: How can I create my own workspace?

From: Husam Aldahiyat

Date: 13 Mar, 2010 15:00:21

Message: 10 of 11

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hng6bt$1f0$1@fred.mathworks.com>...
> "Husam Aldahiyat" <numandina@gmail.com> wrote in message <hnfdmj$3q6$1@fred.mathworks.com>...
>
> > It doesn't work outside nested functions.
> > % There's no workspace field, why? :(
>
> Because only nested functions allow externally scoped workspace variables. Since you scoped the problem to nested functions only in your original post, I obviously focused only on that.

Thanks for the help and time, Matt J and Walter Robinson, but I've found a solution to my problem using the debugging functions.

Subject: How can I create my own workspace?

From: Steven Lord

Date: 15 Mar, 2010 15:42:59

Message: 11 of 11


"Husam Aldahiyat" <numandina@gmail.com> wrote in message
news:hnegtq$js1$1@fred.mathworks.com...
>I don't want to edit the loop counter, and toc isn't very important
>actually, but I want to obtain which variables were used and make new
>variables with the exact same name in my new workspace/function, which have
>the same values as the previous variables. Also, this needs to be general
>(no passing on information from one function to another).
>
> I think I'm aiming too high but maybe there's something out there?

What's your use case? Why are you trying to do this? It sounds like you're
trying to "poof" variables into another function's workspace, and that's a
Bad Idea in general.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

No tags are associated with this thread.

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.

Contact us