Calculate mean of a matrix columnwise if a condition is met

조회 수: 7 (최근 30일)
susman
susman 2020년 8월 12일
댓글: hosein Javan 2020년 8월 12일
I am stuck on a small coding issue.
I have a big matrix "A" and a scalar value "b" and I want to determine,
Expected value = Mean ( A -b) if A < b
for example if,
A = [10 10 10;10 5 5;10 5 5]
b = 10
C = b - A
C = [0 0 0; 0 -5 -5; 0 -5 -5]
Calculate mean = Expectation [C / (A<b ]
calculations of mean should be columnwise.
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2020년 8월 12일
Could you complete your example? What is the resulting value(s) of C for the example you shared?

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

채택된 답변

hosein Javan
hosein Javan 2020년 8월 12일
A = [10 10 10;10 5 5;10 5 5]
b = 10
C = b - A
C(A>=b) = nan % replace all data out of specified range by nan
mean(C,'omitnan') % mean columns omitting nan
  댓글 수: 2
susman
susman 2020년 8월 12일
Thats absolutely perfect! Thanks
hosein Javan
hosein Javan 2020년 8월 12일
you're welcome. don't mention it.

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

추가 답변 (0개)

카테고리

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