0

how do i obtain multiple max values in an array simultaneously in matlab? for example in a row or column of a matrix if I have an array [45 12 56 98 67 89 23 100 201 345] how can i get the highest values simultaneosly

1 Answer 1

3

You can use unique which will by default sort the array in ascending order (so you'll want to flip it), then you can the first N values that you care about.

vals = flip(unique(data));
maxima = vals(1:N);

If you don't care about unique maxima, then just use sort instead.

vals = sort(data, 'descend');
maxima = vals(1:N);

If instead you want the maximum or minimum along a certain row/column, you can use the dim input to min or max.

% Maximum per column
maxima = max(data, [], 1);

% Maximum per row
maxima = max(data, [], 2);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.