add non zeros in array to my probability formular

조회 수: 1 (최근 30일)
Martin
Martin 2018년 10월 20일
댓글: Martin 2018년 10월 20일
Imagine I have probabilities in this array:
a = [ 0.4 0 0 ; 0.6 0.5 0.8 ; 0 0.3 0.3 ];
then I want to add all non-zeros to this formula:
end_probability = 1 - (1 - a(1,1));
end_probability = 1 - ((1 - a(2,1)) * (1 - a(2,2)) * (1 - a(2,3)));
end_probability = 1 - ((1 - a(3,2)) * (1 - a(3,3)));
Any idea of how to make some clean code out of this and put the result into a vector? a can be larger in rows and columns...

채택된 답변

Bruno Luong
Bruno Luong 2018년 10월 20일
ep = 1 - prod(1-a,2)
  댓글 수: 1
Martin
Martin 2018년 10월 20일
wow I was working with if and stuff.. Very elegant, thanks!

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by