How to make a loop to average the values?

2 visualizzazioni (ultimi 30 giorni)
Hi guys,
I have written
BV_14_L_mean = mean(BV_14_L,2);
BV_14_L_std = std(BV_14_L,0,2);
BV_16_L_mean = mean(BV_16_L,2);
BV_16_L_std = std(BV_16_L,0,2);
BV_18_L_mean = mean(BV_18_L,2);
BV_18_L_std = std(BV_18_L,0,2);
BV_20_L_mean = mean(BV_20_L,2);
BV_20_L_std = std(BV_20_L,0,2);
BV_22_L_mean = mean(BV_22_L,2);
BV_22_L_std = std(BV_22_L,0,2);
BV_L_mean_graph = errorbar(BV_14_L_mean,BV_14_L_std,'-','LineWidth',2)
view([90, -90])
hold on
errorbar(BV_16_L_mean,BV_16_L_std,'--','LineWidth',2)
view([90, -90])
hold on
and so on..
I would like to make the codes below shorter by using a for loop.
BV_14_L_mean = mean(BV_14_L,2);
BV_14_L_std = std(BV_14_L,0,2);
so on
BV_14_L to BV_22_L are 10*5 doubles.
How should I do it?

Risposta accettata

Yazan
Yazan il 2 Lug 2021
If you want to use a for loop, you can do this
for j=14:22
eval(sprintf('BV_%g_L_mean = mean(BV_%g_L,2);', j, j));
eval(sprintf('BV_%g_L_std = std(BV_%g_L,0,2);', j, j));
end
  3 Commenti
Yazan
Yazan il 2 Lug 2021
Just modify the looping
j=14:2:22
Hyeonjun Park
Hyeonjun Park il 2 Lug 2021
Oh right that was a pretty stupid question. Thank you!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by