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
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);