how to select the second maximum value for an array.
122 次查看(过去 30 天)
显示 更早的评论
A=[20 60 80 100 75 90 35 55]
with respect to A if i use the command max(A) it gives 100.
But i need to choose the second maximum value 90.
Could anyone please help me on this.
1 个评论
Stephen23
2020-1-7
Is there any reason why the answers to your previous questions on this topic no longer work?:
回答(2 个)
Lucademicus
2020-1-7
One way would be to sort the array and take the value of the second to last value.
[a,b] = sort(A);
maximum = A(b(end-1));
There are multiple ways to achieve this. I'm sure somebody will come up with a nicer oneliner, but this should do your job.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!