How to flush out all variables before each iteration

6 ビュー (過去 30 日間)
Mekala balaji
Mekala balaji 2016 年 5 月 8 日
コメント済み: Geoff Hayes 2016 年 5 月 8 日
Hi,
I have 100 iterations, 50~100 variables. I want to flush out all variables before each iteration. I am doing now like variable1=[];variable2=[] ---variable100=[];. But I want to know is there any command which can do this in a single command.
many thanks in advance,
  1 件のコメント
Stephen23
Stephen23 2016 年 5 月 8 日
100 variables! That is a poor way to write code. You should put all of your variables in a structure: this would be easier to manage, and makes tasks like this trivial.

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

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 5 月 8 日
Mekala - why do you have one hundred variables? Can't you use an array or matrix to store all of this data in one convenient variable? For example, if each variable is of the same dimension, say mxn, then you could create an mxnx100 array as
variableData = zeros(m,n,100);
Else, if each variable is of a different dimension, then just use a cell array to store all of this data as
variableData = cell(100,1);
  2 件のコメント
Mekala balaji
Mekala balaji 2016 年 5 月 8 日
Sir/Madam,
Thanks for your kind help,
In each iteration, I have multiple "for loops" to filter the required data, and also different data. Variable data size is different.
in different loop, data matrix size is different.
Sincerely,
Geoff Hayes
Geoff Hayes 2016 年 5 月 8 日
Since the variable data size is different, then use a cell array or, as Stephen has suggested, a structure.

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

その他の回答 (1 件)

Ahmet Cecen
Ahmet Cecen 2016 年 5 月 8 日
Without more information, no way for me to suggest a better way to do this, but check:
clearvars -except VarYouwantToKeep1 VarYouwantToKeep2
assuming you want to flush more variables than you want to keep...

カテゴリ

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