Problem with the mean function
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone,
I've got a little pb with the 'mean' function :
My matrix has a class 'double' on my workspace : <70080*1 double> I would like to do an average of those values :
moyenne = mean(refoulement(1:8760,1)) and the answer is NaN. The values are positives.
Do you have an idea ?
Thanks !
댓글 수: 0
채택된 답변
Kye Taylor
2012년 5월 2일
Try this
meanWithoutNans = mean(refoulement(~isnan(refoulement)));
댓글 수: 2
Kye Taylor
2012년 5월 2일
I interpret you question as, "How do I take the mean of rows in a matrix and avoid the nans?"
To do that, try
meanOfRowsWithoutNans = zeros(size(refoulement,1),1);
for i = 1:size(refoulement,1) % for each row
meanOfRowsWithoutNans(i) = ...
mean(refoulement(i,~isnan(refoulement(i,:))));
end
추가 답변 (3개)
Image Analyst
2012년 5월 2일
What does this say:
hasNans = max(isnan(refoulement))
I want to see if there are any nan's in your original matrix.
댓글 수: 0
Sean de Wolski
2012년 5월 2일
If you have the Stats Toolbox, take a peak at:
doc nanmean
Also this FEX submission:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!