How to make a loop to average the values?

1 次查看(过去 30 天)
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?

采纳的回答

Yazan
Yazan 2021-7-2
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 个评论
Hyeonjun Park
Hyeonjun Park 2021-7-2
Oh right that was a pretty stupid question. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by