MATLAB: How to obtain maximum values in the y-axis and corresponding x-values in a given dataset

maximum values

Hi, I got a dataset (1031×2 matrix) consisting of a bunch of datapoints for a profile, where the first column represents the x-axis, the second column the y-axis. I need the ten highest values in the y-axis and the corresponding x-values. I tried it via sorting but then I get the ten highest values for the x-axis as well, which of course, are not the corresponding values to the computed highest y-values…
Thanks in advance!
sortedFw = sort(footwall, 'descend'); % sort dataset descending
FwMax10 = sortedFw(1:10) ; % obtain 10 max values
n = sortedFw(10,:);
FwMax10_detour = footwall;
FwMax10_detour(FwMax10_detour<n)=NaN

Best Answer

Let a - your array (1032x2)
B = sortrows(a,-2);
out = B(1:10,:);