MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

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

64 correct solutions
55 incorrect solutions

Last solution submitted on Jul 10, 2015

1 player likes this problem

1 player likes this solution

2 Comments

Ned Gulley
on 15 Oct 2013

Clever! If the system doesn't work properly, work around it.

Alfonso Nieto-Castanon
on 15 Oct 2013

Thanks :) in retrospect I probably should have overloaded isequal with isequalwithequalnans instead, but I guess this makes a similar point... (and if you are interested, the whole 'singularity' series of problems is devoted to "work arounds" for this sort of ill-defined testsuites)

4 Comments