フィルターのクリア

Changing variable after each loop iteration

12 ビュー (過去 30 日間)
Rooy
Rooy 2013 年 2 月 20 日
編集済み: Walter Roberson 2022 年 11 月 7 日
Will it be possible to change the variable or assign an new variable after each loop iteration
a=9
while a>0
a=input('Example')
end
I don't want to collect it in an array.
Thank you
  1 件のコメント
Rooy
Rooy 2013 年 2 月 20 日
This would a question collecting input for gears 1,2,3,4,5,6,7...... in the loop.

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

採用された回答

Image Analyst
Image Analyst 2013 年 2 月 20 日
In my opinion that's ridiculous. Collect it in an array - the whole rest of the world does it, so why can't you? Anyway, your code does change the variable value, just not its name.
  3 件のコメント
Image Analyst
Image Analyst 2013 年 2 月 20 日
編集済み: Image Analyst 2013 年 2 月 20 日
The alternative, shown in the FAQ http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F is more complicated than just using arrays:
counter = 1;
a(counter) = 1;
while a(counter)>0
a(counter) = input('Example')
counter = counter + 1;
end
I think your friend could certainly grasp this concept that even a high school kid could understand.
Roman Henry
Roman Henry 2022 年 11 月 7 日
編集済み: Walter Roberson 2022 年 11 月 7 日
such a poor response

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

その他の回答 (1 件)

Youssef  Khmou
Youssef Khmou 2013 年 2 月 20 日
Yes, you can but your example is not clear using infinite loop and an input each iteration .
for t=1:10
x=t; % each iteration x= t={1,,,,10} x(final)=10
end

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by