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...

Answers (1)

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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 14 May 2019

Answered:

Jan
on 14 May 2019

Community Treasure Hunt

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

Start Hunting!