フィルターのクリア

dynamic variable names in a loop

6 ビュー (過去 30 日間)
genesis
genesis 2013 年 7 月 16 日
編集済み: Stephen23 2019 年 6 月 25 日
hi,
i want to make new variables every time the user key in something. for example, the first user key in 'A', then i want it to be saved in x1. when the second user key in 'B', i want it to be saved in x2.

採用された回答

Stephen23
Stephen23 2016 年 1 月 12 日
編集済み: Stephen23 2019 年 6 月 25 日

その他の回答 (1 件)

Iain
Iain 2013 年 7 月 16 日
Thats a really bad idea.
x={}; %real code
loop starts here %pseudocode
stuff = your input function that gets an input %pseudocode
x{end+1} = stuff; %real code - the way you should do it
eval(['x' num2str(loop_counter) ' = stuff;']) % real code - slow and awkward until the loop counter gets huuuge.
loop ends here %pseudocode
x{1}
x{2}
x{3}
If the input is limited to a single character, then the () can and should be swapped for {}.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by