How can I make this source code simple?
Afficher commentaires plus anciens
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...
Réponses (1)
Jan
le 14 Mai 2019
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.
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!