Matlab 2007

10 vues (au cours des 30 derniers jours)
developer
developer le 28 Avr 2011
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?

Réponses (2)

Matt Fig
Matt Fig le 28 Avr 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 commentaire
Robert Cumming
Robert Cumming le 30 Avr 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.

Connectez-vous pour commenter.


Robert Cumming
Robert Cumming le 28 Avr 2011
Thats whats supposed to happen, see mathworks help to understand the difference between functions and scripts.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by