A simple question

1 次查看(过去 30 天)
Alessandro Innocenti
Hi! I have multiple NaNs in my 60x3 matrix. I want to average out the first three values for each column, without considering NaN.
For example:
1 2 3
Nan 5 6
7 8 Nan
10 11 12
13 Nan 15
16 17 18
Mean:
4 (1+7/2) 5 (8+2+5/3) 4.5 (6+3/2)
13(10+13+16/3) 14(11+17/2) 15 (12+15+18)
I think it isn't difficult but I'm not very able with Matlab.. Thank you. Ale

采纳的回答

Richard
Richard 2012-6-21
If you have 60 rows and 3 columns in matrix 'a' then you can find the mean of each row i.e. the first three values as you stated above then you should use:
nanmean(a,2);
nanmean calculates the mean without considering the nan and the 2, tells matlab to calculate the mean along the second dimension i.e. for each row. stating nanmean(a,1) would calculate the mean for each individual column thus returning 60 values. Hope this helps

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by