How to make a loop to average the values?
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Yazan
on 2 Jul 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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!