请问一下,用matlab可以把这组数中 x相同时y最小 和y相同时x最小的行提取出来吗?

请问一下,用matlab可以把这组数中 x相同时y最小 和y相同时x最小的行提取出来吗?

img

img


clear all;
close all;
clc;
x=[3;4;5;5;6;6;7;7];
y=[3;3;2;3;1;2;1;2];
data=[x,y];
temp=[];
datanew=[];
tx=unique(data(:,1));
for i=1:size(tx,1)
    for j=1:size(data(:,1),1)
        if tx(i)==data(j,1)
            temp=[temp;data(j,:)];
        end
    end
    if size(temp,1)>1
        [~,loc]=min(temp(:,2));
        datanew=[datanew;temp(loc,:)];
    else
        datanew=[datanew;temp];
    end
    temp=[];
end
% datanew即提取出的x相同时y最小

y相同时x最小 可将上述代码修改即可