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
Jan 2019년 5월 14일

0 개 추천

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에 대해 자세히 알아보기

질문:

2019년 5월 14일

답변:

Jan
2019년 5월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by