find elements which has minmum and maximum probability in an array

1 view (last 30 days)
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)

Accepted Answer

Tommy
Tommy on 16 Apr 2020
Edited: Tommy on 16 Apr 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

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!