repeat n times vector with name index
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
i hope someone can help me
i need to repeat these 4 lines of code n times with the variable {i} changing from 1 until n
E{i}=trapz(days,D{i});
e{i}=D{i}(1,1);
ee{i}=D{i}(5,1);
Etotal{i}=E{i}A+570*e{i}+2330*ee{i};
D{i} is a series of data vectors imported ( D1 D2 .... Dn) (the index "i" in this case refers only to the name of the vector)
1 Commento
Stephen23
il 1 Dic 2022
"D{i} is a series of data vectors imported ( D1 D2 .... Dn) (the index "i" in this case refers only to the name of the vector)"
Best solution: fix the data importing, so that you are not forcing meta-data into variable names. Use indexing.
Risposte (1)
Fangjun Jiang
il 1 Dic 2022
for i=1:n
E{i}=trapz(days,D{i});
e{i}=D{i}(1,1);
ee{i}=D{i}(5,1);
Etotal{i}=E{i}A+570*e{i}+2330*ee{i};
end
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!