Matlab 2007
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Matt Fig
el 28 de Abr. de 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 comentario
Robert Cumming
el 30 de Abr. de 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
el 28 de Abr. de 2011
Thats whats supposed to happen, see mathworks help to understand the difference between functions and scripts.
0 comentarios
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!