add non zeros in array to my probability formular

1 visualizzazione (ultimi 30 giorni)
Martin il 20 Ott 2018
Commentato: Martin il 20 Ott 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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Bruno Luong il 20 Ott 2018
ep = 1 - prod(1-a,2)
1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Martin il 20 Ott 2018
wow I was working with if and stuff.. Very elegant, thanks!

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by