Time averaged values for each 100 iteration

1 visualizzazione (ultimi 30 giorni)
m m il 1 Gen 2020
Modificato: Matt J il 1 Gen 2020
i want to calculate the time averged value for each 100 iteration. knowing that my program is like this :
for m = 1:20000 %time iteration
for k = 1:1000
X(k)=
end(k)
if m>10000
%here i want to calculate the aceraged valu of X but for each 100 itaetation (m) i want to store the Xaveraged
for k = 1:1000
Xaveraged(k)=Xaveraged(k) + X(k)
end
end
end(m)
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposte (2)

Matt J il 1 Gen 2020
Modificato: Matt J il 1 Gen 2020
Xaveraged=mean(reshape(X,100,[]));
1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
m m il 1 Gen 2020
thank you Matt for your rely.
but i dont intersttand Xaveraged=mean(reshape(X,100,[])); because Xaveraged depends on K, i want for each 100 m iteration store the values of Xaveraged in each K.

Accedi per commentare.

Matt J il 1 Gen 2020
Modificato: Matt J il 1 Gen 2020
Maybe this is what you want.
X=nan(1000,20000); %pre-allocate
for m = 1:20000 %time iteration
for k = 1:1000
X(k,m)=... %store for all k and m
end
end
%compute after iterations all finished
Xaveraged=squeeze( mean(reshape(X,1000,100,[]),2) );
1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Matt J il 1 Gen 2020
Modificato: Matt J il 1 Gen 2020
Or, if you want to be more conservative with memory (but why??), then a variation is
X=nan(1000,100); %pre-allocate
Xaveraged=nan(1000,200); %pre-allocate
for s=1:200
for t=1:100
m=s*t; % time iteration number
for k = 1:1000
X(k,t)=...
end
end
Xaveraged(:,s)=mean(X,2);
end

Accedi per commentare.

Categorie

Scopri di più su Boundary Conditions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by