How to find 3 maximum element in array and their indices without sorting
Show older comments
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 Comments
Guillaume
on 21 Jan 2016
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
on 21 Jan 2016
Stephen23
on 21 Jan 2016
"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.
Accepted Answer
More Answers (0)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!