Mean of an Array Containing some NAN Elements

조회 수: 5 (최근 30일)
Fabio Taccaliti
Fabio Taccaliti 2022년 7월 7일
답변: Vijeta Singh Yadav 2022년 7월 7일
Hello, I have two different arrays, A2 (96x96 doubles) and A3 (96x96x96 doubles), in both these arrays some elements inside are NAN.
I would like to compute the mean (single value for each array) of all the non-NAN values, how can I do it?
I tried with mean(A2) and mean(A3) but is not working

채택된 답변

KSSV
KSSV 2022년 7월 7일
편집: KSSV 2022년 7월 7일
Read the doc of mean, there is option of omitting nan.
A = [1 2 NaN 3 4 NaN] ;
mean(A,'omitnan')
ans = 2.5000
In older versions it is nanmean.
  댓글 수: 2
Fabio Taccaliti
Fabio Taccaliti 2022년 7월 7일
Thanks, how can I do the mean of all the components, because right now is giving me a 1x96 array
KSSV
KSSV 2022년 7월 7일
Again read the doc, you cn specify the dimension to calculate the mean.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Vijeta Singh Yadav
Vijeta Singh Yadav 2022년 7월 7일
M = mean(___,nanflag)
This function will define whether to exclude or include NaN values from the computation of any previous syntaxes.
It has the following 2 types:
  • Mean(X,’omitNaN’): It will omit all NaN values from the calculation
  • Mean(X,’includeNaN’): It will add all the NaN values in the calculation.
Refer to Matlab Documentation for more information.

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by