How to calculate mean within a for Loop

조회 수: 8 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by