Matlab 2007

7 次查看(过去 30 天)
developer
developer 2011-4-28
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?

回答(2 个)

Matt Fig
Matt Fig 2011-4-28
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 个评论
Robert Cumming
Robert Cumming 2011-4-30
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
Robert Cumming 2011-4-28
Thats whats supposed to happen, see mathworks help to understand the difference between functions and scripts.

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by