MATLAB Answers

Martin
0

add non zeros in array to my probability formular

Asked by Martin
on 20 Oct 2018
Latest activity Commented on by Martin
on 20 Oct 2018
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...

  0 Comments

Sign in to comment.

1 Answer

Answer by Bruno Luong
on 20 Oct 2018
 Accepted Answer

ep = 1 - prod(1-a,2)

  1 Comment

wow I was working with if and stuff.. Very elegant, thanks!

Sign in to comment.