Effacer les filtres
Effacer les filtres

have a func(:,:,t) that I took the average of, how do I create just an array of those values?

1 vue (au cours des 30 derniers jours)
So I have iterations of a 2-D temperature profile, in which I do
Tavg = mean(mean(T(:,:,:)));
where T(i,j,t) is what I used.
Anyways, "Tavg" spits back a matrix of size [1 1 "#timesteps"]
Not sure why it's that size because when I type "Tavg" it gives me:
Tavg(:,:,17280) =
306.7141
an actual value. (note, that's one of thousands necessary for my script)
How would I take all those computed averages to be able to plot them against time? Seems trivial, but I can't figure it out.

Réponse acceptée

Cedric
Cedric le 19 Mar 2013
Modifié(e) : Cedric le 19 Mar 2013
MEAN computes a mean along the 1st non-singleton dimension of its (1st) arg, unless you provide the dim as a second arg.
>> A = rand(2)
A =
0.4218 0.7922
0.9157 0.9595
>> mean(A)
ans =
0.6687 0.8758
that was along dim 1. Now if A had been a 1x2 array (dim 1 is a singleton):
>> A = rand(1,2)
A =
0.6557 0.0357
>> mean(A)
ans =
0.3457
you see that the mean was performed over dim 2 (as dim 1 is a singleton dimension).
In your case, the inner MEAN performs a mean along dim 1 and reduces it to singleton. The outter MEAN performs a mean along dim 2 (1st non-singleton). You are left with a 3D array with two singleton dims, which is what is displayed..
>> A = rand(2, 2, 3)
A(:,:,1) =
0.8491 0.6787
0.9340 0.7577
A(:,:,2) =
0.7431 0.6555
0.3922 0.1712
A(:,:,3) =
0.7060 0.2769
0.0318 0.0462
>> mean(A) % Along dim 1.
ans(:,:,1) =
0.8916 0.7182
ans(:,:,2) =
0.5677 0.4133
ans(:,:,3) =
0.3689 0.1615
>> mean(mean(A)) % Along dim 1 and 2, but still 3D!
ans(:,:,1) =
0.8049
ans(:,:,2) =
0.4905
ans(:,:,3) =
0.2652
You can actually SQUEEZE singleton dimensions if/when needed:
>> squeeze(mean(mean(A)))
ans =
0.8049
0.4905
0.2652
but you could also permute dimensions:
>> mean(mean(permute(A, [3,1,2]), 3), 2)
ans =
0.8049
0.4905
0.2652
or
>> mean(mean(permute(A, [1,3,2]), 3))
ans =
0.8049 0.4905 0.2652
So .. no, it was not completely trivial ;-)
  2 commentaires
Jon
Jon le 19 Mar 2013
Wow, thorough and perfect answer, Cedric.
Many thanks!
Cedric
Cedric le 19 Mar 2013
My pleasure. Just have a look again at the 1st sentence please; I think that I reworded it while you were posting your comment, so you might not have seen the update!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by