How to calculate mean within a for Loop

8 Ansichten (letzte 30 Tage)
Abu Sayed
Abu Sayed am 16 Jan. 2023
Kommentiert: Mathieu NOE am 16 Jan. 2023
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.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 16 Jan. 2023
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 Kommentare
Abu Sayed
Abu Sayed am 16 Jan. 2023
Thank you So much
Mathieu NOE
Mathieu NOE am 16 Jan. 2023
My pleasure !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by