MATLAB: Secons max number in a vector

secons max number in a vector

Hi I need to find maximum and second maximum number in a vector. Can you please help?
For max, its max(X), but for second max I am unable to figure out.
Your help is appreciated
P

Best Answer

a = max(X);
Y = X(X ~= a);
b = max(Y);