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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by