A simple question
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!