find elements which has minmum and maximum probability in an array

1 次查看(过去 30 天)
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)

采纳的回答

Tommy
Tommy 2020-4-16
编辑:Tommy 2020-4-16
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by