How to calculate mean within a for Loop

9 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Mathieu NOE
Mathieu NOE il 16 Gen 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by