How to find 3 maximum element in array and their indices without sorting
显示 更早的评论
Hi everybody
I have an array like this(its data type is double):
a = {1,4,2,7,1,2,9,11,4,3,1,7,12,3,5,6,2,1}
I want to return 3 or more maximum element with their indices without any changes in the original form of "a" (like sorting it)
thanks in advance
3 个评论
Guillaume
2016-1-21
You're asking to find x1, x2, x3 belonging to a such that:
x1 >= x2 >= x3 >= all other xn
You can call it whatever, but mathematically it is imposing an ordering on the set and that is called sorting.
You may be able to achieve this without calling sort but it is sorting.
mhm
2016-1-21
Stephen23
2016-1-21
"I dont want to sort this array "
Yes you do. Sorting means putting those values into order. You want to select some depending on their order, ergo you want to sort the values. You are contradicting yourself.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!