Matlab 2007
9 views (last 30 days)
Show older comments
I am using matlab 2007 whenever my function completes, all the variables are cleared from my work space, i have check i havenot use clear command anywhere, is there any option that has to be change to retain the variables in workspace?
0 Comments
Answers (2)
Matt Fig
on 28 Apr 2011
I think the problem is that you are calling a function from the base workspace then expecting the variables created in the function to exist in the base workspace? If that is so, you need to understand that functions have their own workspaces. Any variables you need from a function should be passed out or saved from within the function for later loading at the command line.
For example, at the end of the function, put this line:
save myfuncvars
Then from the command line:
load myfuncvars
Now all of the variables in the function are in your base workspace. Be aware that any pre-existing variables which have the same names as a variable in the function will be lost. Thus to be safe, do this at the command line:
MFV = load('myfuncvars');
Then MFV will be a struct containing the function variables as fieldnames.
1 Comment
Robert Cumming
on 30 Apr 2011
If you want to do this I would recommend using the FEX:
http://www.mathworks.com/matlabcentral/fileexchange/27106-putvar
As saving and loading everything from file could be quite inefficient if you have large variables and/or work over a network.
Robert Cumming
on 28 Apr 2011
Thats whats supposed to happen, see mathworks help to understand the difference between functions and scripts.
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!