summation with for loop for all rows in another column

1 回表示 (過去 30 日間)
MUKESH KUMAR
MUKESH KUMAR 2020 年 1 月 13 日
編集済み: Raj 2020 年 1 月 13 日
Capture.JPG
I had following data as attached
h = 1;
I_all size(3154*20)
So hmax = 20;
I1 = I_all(1,1) for first row and I1=I_all(2,1) for 2nd row and so on........
Need F_HL for all 3154 rows..........
  2 件のコメント
Rik
Rik 2020 年 1 月 13 日
What have you tried so far? Especially the version with a for loop seems easy to implement.
MUKESH KUMAR
MUKESH KUMAR 2020 年 1 月 13 日
h=1:20;
F_HL_N = 0;
for i=1:20
F_HL_N = F_HL_N+(I_all(1,i)/I_all(1,1))^2* h(i)^2;
end
F_HL_D = 0;
for i=1:20
F_HL_D=F_HL_D+(I_all(1,i)/I_all(1,1))^2;
end
F_HL = F_HL_N/F_HL_D; % for first row
% now want to do for all 3154 rows in for loop

サインインしてコメントする。

回答 (1 件)

Raj
Raj 2020 年 1 月 13 日
編集済み: Raj 2020 年 1 月 13 日
You are almost there. Put the whole thing in another loop that runs accross all the rows and store F_HL for each row like this:
for ii=1:3154
h=1:20;
F_HL_N = 0;
for i=1:20
F_HL_N = F_HL_N+(I_all(1,i)/I_all(1,1))^2* h(i)^2;
end
F_HL_D = 0;
for i=1:20
F_HL_D=F_HL_D+(I_all(1,i)/I_all(1,1))^2;
end
F_HL(ii) = F_HL_N/F_HL_D; % for iith row
end
Done!

カテゴリ

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