How to calculate standard deviation in double for loop?
2 次查看(过去 30 天)
显示 更早的评论
for j = 1:length(EC)
for k = 1:length(Reff)
eval(['depri',num2str(j),num2str(k),'=','(depi',num2str(1),num2str(j),num2str(k),')./(depi',num2str(2),num2str(j),num2str(k),');']);
end
end
deprir1 = [depri11(10) depri12(10) depri13(10) depri14(10) depri15(10)];
deprir2 = [depri21(10) depri22(10) depri23(10) depri24(10) depri15(10)];
deprir3 = [depri31(10) depri32(10) depri33(10) depri34(10) depri15(10)];
deprir4 = [depri41(10) depri42(10) depri43(10) depri44(10) depri15(10)];
I want to write a function to calculate the standard deviation in the function 'depri' written in the eval expression for both of the loop indices, j and k. So after that, I would be able to calculate the standard deviaiton in each value of depri (deprir1,deprir2,.......) at each point (depri11(10), depri12(10),.....).
0 个评论
回答(1 个)
James Tursa
2021-4-22
The short answer is don't do that. This style of programming has many problems. See this link for alternatives:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!