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),.....).

回答(1 个)

James Tursa
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:
  1 个评论
Wiqas Ahmad
Wiqas Ahmad 2021-4-22
Thank you for your suggestions. I will adopt the alternatives to eval function but my program is too lengthy and will consume more time because I posted here just a portion of my program. On the other hand, this is a recommended program by my supervisor to modify to obtain my results, otherwise I'm not enough expert in programming. What I needed now is to learn how can we calculate the standard deviation in this case using double forloop? After all, I will improve my program to be more efficient.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by