how to use while loop to access workspace values?

I have some value in my workspace. i want to access those value one by one using while loop. so i can find a value which is greater then x. Any help would be grateful

3 件のコメント

jgg
jgg 2016 年 2 月 19 日
編集済み: jgg 2016 年 2 月 19 日
You're almost certainly better off re-structuring your data so that you don't have to iterate through the variables in your workspace. Try storing the values in a sequential array instead.
However, if you REALLY want to do this, you can do as follows:
variables = who;
for i = 1:length(variables)
eval('A = ', variables{i}); %A now stores the i-th variables info
%do stuff to A like A > x or whatever
end
Again, don't do this! It's a bad idea. Restructure your code so you can just loop instead without using eval and dealing with the workspace.
sivalogan satchithanandamoorthy
sivalogan satchithanandamoorthy 2016 年 2 月 19 日
thanks you
jgg
jgg 2016 年 2 月 19 日
If you solve your problem, post an answer below so others can see it.

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

編集済み:

2019 年 6 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by