want to use a 'for' loop to swich between variables, like varname_1+n

3 ビュー (過去 30 日間)
Simon Simon
Simon Simon 2015 年 6 月 10 日
編集済み: Stephen23 2019 年 6 月 19 日
I'm using a syntax to creat variables, in the next step I want to use the variables one by an other in a 'for' loop.
syntax to creat the variables: like A_1, A_2, A_3, ...
for f=1:1:18
a_LLK{f} = 'a_LLK_';
end
varnamelist1 = genvarname(a_LLK);
for l=1:1:18
eval([genvarname(['a_LLK_' num2str(l)]) '= ...']);
end
now I want to put the values of the createt variables in a Matrix.
for m=1:1:18
B_LLK(:,m) = a_LLK_ *'m'*
end
so that it will be count:
B_LLK(:,1) = a_LLK_1
B_LLK(:,2) = a_LLK_2
B_LLK(:,3) = a_LLK_3
. . .
thanks for help
  3 件のコメント
Simon Simon
Simon Simon 2015 年 6 月 10 日
thats just a piec of the function usualy a_LLK_n are fft's in form of matrices. And I will take the inverse of the fft and put the results in B_LLK. Just try to write compact and short;)
Stephen23
Stephen23 2015 年 6 月 10 日
編集済み: Stephen23 2015 年 6 月 10 日
@Simon Simon: Don't create the variables dynamically like this in the first place. Bad programming practices like this should be avoided. Use an N-D array, a cell array or a structure instead.
Beginners often think that it is a great idea to put meta-information is a variable name (e.g. consecutive numbers or test conditions), but really this is programmatically a poor idea: it prevents variable tracking and code checking tools from working, is slow and very buggy.

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

採用された回答

Stephen23
Stephen23 2015 年 6 月 10 日
編集済み: Stephen23 2019 年 6 月 19 日
  2 件のコメント
Simon Simon
Simon Simon 2015 年 6 月 10 日
thank you for answering and you helpfully comment, I try to anderstand and check the many informatons you gave me ;)
Simon Simon
Simon Simon 2015 年 6 月 10 日
great thanks... Much better...

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

その他の回答 (0 件)

カテゴリ

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