A simple question

2 views (last 30 days)
Alessandro Innocenti
Alessandro Innocenti on 21 Jun 2012
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

Accepted Answer

Richard
Richard on 21 Jun 2012
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

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by