find elements which has minmum and maximum probability in an array

1 visualización (últimos 30 días)
i need to get the elements which has minimum and maximum probablities from A = [ 1,2,3,4,5,6,7] & P = [ 0.01,0.01,0.25.0.2,0.25,0.09,0.19] ................
i need output as for min prob either (1 or 2) and for max prob either (3 or 5)

Respuesta aceptada

Tommy
Tommy el 16 de Abr. de 2020
Editada: Tommy el 16 de Abr. de 2020
A = [ 1,2,3,4,5,6,7];
P = [ 0.01,0.01,0.25,0.2,0.25,0.09,0.19];
minprob = A(P==min(P))
maxprob = A(P==max(P))
minprob =
1 2
maxprob =
3 5
(edit) If you want to pick one number among the outputs at random:
A = [ 1,2,3,4,5,6,7];
P = [ 0.01,0.01,0.25,0.2,0.25,0.09,0.19];
minprob = A(P==min(P));
minprob = minprob(randi(1:numel(minprob)))
maxprob = A(P==max(P));
maxprob = maxprob(randi(1:numel(maxprob)))
minprob =
1
maxprob =
5

Más respuestas (0)

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by