confusion during finding out the mean of a 3d vector
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SWARNENDU PAL
am 21 Jul. 2021
Kommentiert: SWARNENDU PAL
am 21 Jul. 2021
I have a 3d vector of size 1498x1498x24. I want to calculate the wholes mean of the vector. I have used two method and got two different result. If anyone please explain this part that will be really helpful. I am giving the code and corresponding result.
mean(mmr_timeseries,'all','omitnan')
Using this i got the value 970.8025. Then i used :
mean(mean(mean(mmr_timeseries,'omitnan'),'omitnan'),'omitnan')
In this case I got 884.2371. I think these two lines are equivalent but I got different result. If ant=yone could please explain this part that will be really helpful. Thank you.
3 Kommentare
Akzeptierte Antwort
Chunru
am 21 Jul. 2021
Bearbeitet: Chunru
am 21 Jul. 2021
A 2-d example (applicable to 3d in principle).
a=[1 2; 3 3; nan 4; nan nan]
% mean of [1 2 3 3 4] after omitting nans
mean(a,'all','omitnan')
% mean for each column (omit nans)
mean(a,'omitnan')
% mean of the above vector , i.e. [2, 3]
mean(mean(a,'omitnan'),'omitnan')
% The following is for 3d (not shown in this example)
mean(mean(mean(a,'omitnan'),'omitnan'),'omitnan')
5 Kommentare
Bruno Luong
am 21 Jul. 2021
. Then which one should be used?
A=[0 1; NaN 1; NaN 1; NaN 1; NaN 1; NaN 1; NaN 1; NaN 1; NaN 1]
mean(mean(A,'omitnan'),'omitnan')
mean(mean(A,'all','omitnan'))
Weitere Antworten (1)
Jonas
am 21 Jul. 2021
the short answer:
your second approach takes mean values of means and the first approach takes the mean value of all elements
2 Kommentare
Walter Roberson
am 21 Jul. 2021
Those work out the same except when there are nan that are being omitted.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!