confusion during finding out the mean of a 3d vector

2 ビュー (過去 30 日間)
SWARNENDU PAL
SWARNENDU PAL 2021 年 7 月 21 日
コメント済み: SWARNENDU PAL 2021 年 7 月 21 日
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 件のコメント
SWARNENDU PAL
SWARNENDU PAL 2021 年 7 月 21 日
Thanks for your reponse sir. But i got different. I dont know what is the problem. Is there any probable reason for this?
Bruno Luong
Bruno Luong 2021 年 7 月 21 日
See Chunru's answer

サインインしてコメントする。

採用された回答

Chunru
Chunru 2021 年 7 月 21 日
編集済み: Chunru 2021 年 7 月 21 日
A 2-d example (applicable to 3d in principle).
a=[1 2; 3 3; nan 4; nan nan]
a = 4×2
1 2 3 3 NaN 4 NaN NaN
% mean of [1 2 3 3 4] after omitting nans
mean(a,'all','omitnan')
ans = 2.6000
% mean for each column (omit nans)
mean(a,'omitnan')
ans = 1×2
2 3
% mean of the above vector , i.e. [2, 3]
mean(mean(a,'omitnan'),'omitnan')
ans = 2.5000
% The following is for 3d (not shown in this example)
mean(mean(mean(a,'omitnan'),'omitnan'),'omitnan')
ans = 2.5000
  5 件のコメント
Bruno Luong
Bruno Luong 2021 年 7 月 21 日
. 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]
A = 9×2
0 1 NaN 1 NaN 1 NaN 1 NaN 1 NaN 1 NaN 1 NaN 1 NaN 1
mean(mean(A,'omitnan'),'omitnan')
ans = 0.5000
mean(mean(A,'all','omitnan'))
ans = 0.9000
SWARNENDU PAL
SWARNENDU PAL 2021 年 7 月 21 日
I think 2nd one is the correct and more meaningful as it gives the mean of all numbers.

サインインしてコメントする。

その他の回答 (1 件)

Jonas
Jonas 2021 年 7 月 21 日
the short answer:
your second approach takes mean values of means and the first approach takes the mean value of all elements
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 7 月 21 日
Those work out the same except when there are nan that are being omitted.
SWARNENDU PAL
SWARNENDU PAL 2021 年 7 月 21 日
technically these two things are same i think. Taking mean of mean and find out the whole mean of a multidimensional vector.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by