Problem 1927. Find nth maximum
Find nth maximum in a vector of integer numbers. Return NaN if no such number exists.
x = [2 6 4 9 -10 3 1 5 -10];
So
- n_max(x,3) would find 3rd maximum value in x which is 5
- n_max(x,8) would find 8th maximum value in x which is -10
- n_max(x,9) would find 9th maximum value in x which is -10
- n_max(x,12) does not exist so return NaN
Solution Stats
Problem Comments
-
4 Comments
I think the test cases are not correct. Can you check this?
The test cases expect isequal(NaN,NaN) to return true. This is wrong.
please use the function "isquealn" http://www.mathworks.de/de/help/matlab/ref/isequaln.html
I went ahead and made the test suite change that José suggested above.
Solution Comments
Show commentsProblem Recent Solvers893
Suggested Problems
-
Program an exclusive OR operation with logical operators
745 Solvers
-
Flag largest magnitude swings as they occur
688 Solvers
-
Remove entire row and column in the matrix containing the input values
540 Solvers
-
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
395 Solvers
-
510 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!