How to mean all array?

조회 수: 3 (최근 30일)
sky walker
sky walker 2021년 6월 16일
댓글: KSSV 2021년 6월 16일
Hi, im using matlab r2018a
lets say i have array
A = [NaN 1 1; 2 NaN 2; 1 NaN 2; 4 2 2]
how to get mean of all of it?
i need the result is 1.888889
i try using
z = mean(A(:))
but the answer is
z = NaN

채택된 답변

KSSV
KSSV 2021년 6월 16일
A = [0 1 1; 2 3 2; 1 3 2; 4 2 2] ;
iwant = mean(A(:))
iwant = 1.9167
  댓글 수: 2
sky walker
sky walker 2021년 6월 16일
thanks for your answer, i change my question. but already find the solution
im using
iwant = mean(A(:),'omitnan')
KSSV
KSSV 2021년 6월 16일
You also have the fucntion nanmean.
A = [NaN 1 1; 2 NaN 2; 1 NaN 2; 4 2 2] ;
iwant = nanmean(A(:))
iwant = 1.8889

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 16일
format long g
A = [NaN 1 1; 2 NaN 2; 1 NaN 2; 4 2 2]
A = 4×3
NaN 1 1 2 NaN 2 1 NaN 2 4 2 2
mean(A, 'all', 'omitnan')
ans =
1.88888888888889
  댓글 수: 1
sky walker
sky walker 2021년 6월 16일
Thanks, but i already try that before, but im working in matlab R2018a
so thats not working.
but i already find the solution, im using
mean(A(:),'omitnan')

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

카테고리

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