Clearing everything except variables

3 ビュー (過去 30 日間)
Gregory Jones
Gregory Jones 2011 年 4 月 27 日
Is there a convenient way to do a "clear all" but not remove all the variables? I want to clear everything that isn't a variable. I have a spontaneous problem in 2010a where something gets cached and disrupts my ADODB database connection. Clear All will fix it, but it also clears my variables. Thanks -Greg

回答 (6 件)

Sean de Wolski
Sean de Wolski 2011 年 4 月 27 日
And probably faster that save and load
S = struct('var1',var1); %etc
setappdata(0,'S',S);
clear all;
S = getappdata(0,'S');
var1 = S.var1;
You could save them directly/dynamically as well (i.e. not in a struct, the struct is just nice for compactness)
  10 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 5 月 2 日
@Fangjun: If you have hundreds of variables then you're doing something else wrong. Store them in a cell array or a struct and then use appdata once.
@Andrew: That's why I typically use underscores &| numbers.
Fangjun Jiang
Fangjun Jiang 2011 年 5 月 2 日
I am curious to know what final approach Gregory Jones took to solve his original problem. I sense he might have many variables. "clear all" works but we couldn't seem to eliminate its undesired side effect (clear variables). The best approach, I would think, is to find out the exact and exclusive effects of "clear all". Is it the combination of "clear variables", "clear functions", "clear mex", "clear import" etc? Then, Greg needs to find out which one of these "clear" commands actually did the trick.

サインインしてコメントする。


Fangjun Jiang
Fangjun Jiang 2011 年 4 月 27 日
save;
clear all;
load;

Arnaud Miege
Arnaud Miege 2011 年 4 月 27 日
Have you tried the following?
clear classes
clear functions
clear import
clear mex
Arnaud
  2 件のコメント
Gregory Jones
Gregory Jones 2011 年 4 月 27 日
clear classes will clear variables, I think!
Arnaud Miege
Arnaud Miege 2011 年 4 月 27 日
You're right, sorry!!

サインインしてコメントする。


Andrew Newell
Andrew Newell 2011 年 4 月 27 日
You could try
clear functions import java mex

Paulo Silva
Paulo Silva 2011 年 4 月 27 日
save MyWorkVars
matlabrc
load MyWorkVars
delete(MyWorkVars)
  2 件のコメント
Gregory Jones
Gregory Jones 2011 年 4 月 27 日
The load-and-save are not very practical if I am working with a gig of variables, since the process is quite slow.
Sean de Wolski
Sean de Wolski 2011 年 4 月 27 日
Hence, setappdata/getappdata!

サインインしてコメントする。


Andrew Newell
Andrew Newell 2011 年 4 月 28 日
Another thing to try is
pack

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by