How to calculate mean within a for Loop

9 次查看(过去 30 天)
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

更多回答(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