Perofrming statistics over non-zero elements of mXn array

I would like to perform statistics, e.g. averaging (or any other function, for that matter), over the non-zero elements of an mXn array with more than one column. For example:
so that the result will then be a vector of length n. How is this possible without using a for/loop?

답변 (1개)

Adam
Adam 2017년 2월 10일
array( array == 0 ) = NaN;
nanmean( array )

댓글 수: 2

I need to have the financial or statistic toolbox to perform this.
Adam
Adam 2017년 2월 10일
편집: Adam 2017년 2월 10일
If you have a recent enough version of Matlab then
mean( array, 'omitnan' )
should do the same. It is hard to find out when additions like this were made to functions that have been around for ages though, unlike brand new functions where we can tell from the 'Introduced...' text at the bottom of the documentation page.
Looks like you need R2015a or later for this version of mean

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2017년 2월 10일

편집:

2017년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by