how can i make a function which will return the largest and the second largest component?
Show older comments
how can i make a function that accepts as input a vector of integers, which will return the largest and the second largest component of the vector for the first i think that is max1=max(max(C)) any idea for max2?
Accepted Answer
More Answers (1)
Or:
if sum(C==max(C))==1
second = max(C(C<max(C)));
else
second = max(C);
end
i.e. test if the maximum is unique, if the max is not unique the second is equal to max(C)
Categories
Find more on Creating and Concatenating 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!