How to calculate standard deviation in double for loop?

1 view (last 30 days)
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),.....).

Answers (1)

James Tursa
James Tursa on 22 Apr 2021
The short answer is don't do that. This style of programming has many problems. See this link for alternatives:
  1 Comment
Wiqas Ahmad
Wiqas Ahmad on 22 Apr 2021
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!