Nested mean function with omitnan
3 views (last 30 days)
Show older comments
Commented: Stefan Th. on 16 Mar 2023
Not sure if this behavior is intentional. When I have an array, let's say:
And I want to calculate the mean over the second dimension first, then the first one:
The result is 2.66, which is clearly just (1+3+4)/3, and so it's the same as:
I'm aware that this is exactly what it says in the documentation, but it's still unexpected. What I would have expected would be the same as:
Which in this case gives the (imho correct) result of 2.25, so (1+(3+4)/2)/2
Am I missing something?
Jan on 16 Mar 2023
The problem is here: "What I would have expected would be the same as". This is not the way mean('omitnan') is working. So if you expect something else, you have to write the code to do it as you want it.
If it is explained in the documentation, there is no reason to expect something else. The behavior you expect would not match my intuition for [NaN, 1; NaN, 2].
More Answers (0)
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!