How to calculate mean within a for Loop

6 ビュー (過去 30 日間)
Abu Sayed
Abu Sayed 2023 年 1 月 16 日
コメント済み: Mathieu NOE 2023 年 1 月 16 日
f=linspace(0,1e9,20);
beta=rand(1,20);
alpha=pi/2;
theta=pi/4
phi=pi/4;
for n=1:length(beta)
I_nec=I_xy_total_scl_network_nec_f(f,mu,epsilon,x_1,y_1,z_1,x_2,y_2,z_2,r_0,E_0,beta(n),alpha,theta,phi,Z_1_n,Z_2_n,line_no,terminal,20);
mean_numerically=squeeze(mean(abs(I_nec(:,:,:)).^2));
end
I am trying to calculate the mean which must contain 1x20 value, but this mean_numerically give only one value. Can anyone give me some idea how can I calculate this.

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 1 月 16 日
hello
you have to index your output (mean_numerically(n)) , otherwise it get's overwritten at each iteration
for n=1:length(beta)
I_nec=I_xy_total_scl_network_nec_f(f,mu,epsilon,x_1,y_1,z_1,x_2,y_2,z_2,r_0,E_0,beta(n),alpha,theta,phi,Z_1_n,Z_2_n,line_no,terminal,20);
mean_numerically(n)=squeeze(mean(abs(I_nec(:,:,:)).^2));
end
  2 件のコメント
Abu Sayed
Abu Sayed 2023 年 1 月 16 日
Thank you So much
Mathieu NOE
Mathieu NOE 2023 年 1 月 16 日
My pleasure !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by