How to calculate standard deviation in double for loop?

조회 수: 1 (최근 30일)
Wiqas Ahmad
Wiqas Ahmad 2021년 4월 22일
댓글: Wiqas Ahmad 2021년 4월 22일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by