필터 지우기
필터 지우기

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