How can I make this source code simple?
古いコメントを表示
lt_2 = corr(data_1,data_2)
lt_3 = corr(data_1,data_3)
lt_4 = corr(data_1,data_4)
lt_5 = corr(data_1,data_5)
lt_6 = corr(data_1,data_6)
lt_7 = corr(data_1,data_7)
lt_8 = corr(data_1,data_8)
lt_9 = corr(data_1,data_9)
lt_10 = corr(data_1,data_10)
Hi? I do not really know, so I ask questions :(
I created the source code as shown in the example above.
Can I make it simple to loop through each matrix call?
thanks...
回答 (1 件)
Jan
2019 年 5 月 14 日
Hiding indices in the names of variables forces you to write such code. See TUTORIAL: How and why to avoid Eval
When you use arrays instead, you can eitehr use a loop or vectorization:
ltData = cell(1, 10);
for k = 2:10
ltData{k} = corr(data_1, data{k});
end
"lt" is a Matlab operator, therefore it is recommended not to use it as name of a variable.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!