フィルターのクリア

Changing Variable Name during "While" loop

3 ビュー (過去 30 日間)
Katy Weihrich
Katy Weihrich 2015 年 9 月 15 日
編集済み: Stephen23 2019 年 6 月 19 日
Hello,
I am writing with a "while" comment, and would like to change my variable name in each loop.
x = 1;
while x<=n
if Choice_Accuracy(x,1) == 1
Choice_RT_x = Choice_Input(x,1)
else Choice_RT_x = 0
end
x = x + 1:
end
Could someone tell me how I can Change the variable name "Choice_RT_x" to "Choice_RT_1", "Choice_RT_2", "..." with each loop? I know there are a lot of questions like these, but they are all with a "for" and I really don't understand it.
Thank you very much!

回答 (3 件)

Walter Roberson
Walter Roberson 2015 年 9 月 15 日

Jae Song
Jae Song 2015 年 9 月 15 日
You can use the 'eval' function. Please see the following code:
x = 1;
while x<=n
if Choice_Accuracy(x,1) == 1
eval(['Choice_RT_' num2str(x) '= Choice_Input(x,1)']);
else
eval(['Choice_RT_' num2str(x) ' = 0']);
end
x = x + 1:
end
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 9 月 15 日
This is not recommended!!
Katy Weihrich
Katy Weihrich 2015 年 9 月 15 日
Thank you very much!

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


Luis Gomes Perini
Luis Gomes Perini 2015 年 9 月 15 日
編集済み: Luis Gomes Perini 2015 年 9 月 15 日
Hi,
it my help:
x = 1;
while x<=n
if Choice_Accuracy(x,1) == 1
eval(['Choice_RT_' num2str(x) '=Choice_Input(x,1);']);
else eval(['Choice_RT_' num2str(x) '=0;'])
end
x = x + 1;
end
Cheers
  1 件のコメント
Walter Roberson
Walter Roberson 2015 年 9 月 16 日
This is not at all recommended!

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by