Matlab 点的Nx2矩阵[x1 y1;x2 y2;等],为每个唯一的x获得最高的y值

Matlab 点的Nx2矩阵[x1 y1;x2 y2;等],为每个唯一的x获得最高的y值,matlab,vectorization,Matlab,Vectorization,我正试图找到一种惯用的方法来做这件事 基本上,我有一个Nx2矩阵的点的形式 A=[34;35;45;4,6;73] 我希望我的输出是[35;46;73]。换句话说,我想要每个唯一的x值以及与该x相关的最大y值 我希望会有某种 unique(A, 'rows', 'highestterm', 2) 方法,但找不到任何内容。有人能想出一个矢量化的方法来解决这个问题吗?我可以很容易地在for循环中完成,但如果可能的话,我希望避免这种情况。我不知道有任何一个调用,就像您希望的那样。但是,它可以像下面

我正试图找到一种惯用的方法来做这件事

基本上,我有一个Nx2矩阵的点的形式

A=[34;35;45;4,6;73]

我希望我的输出是[35;46;73]。换句话说,我想要每个唯一的x值以及与该x相关的最大y值

我希望会有某种

unique(A, 'rows', 'highestterm', 2) 

方法,但找不到任何内容。有人能想出一个矢量化的方法来解决这个问题吗?我可以很容易地在for循环中完成,但如果可能的话,我希望避免这种情况。

我不知道有任何一个调用,就像您希望的那样。但是,它可以像下面的代码那样非常紧密地完成(并且完全矢量化)

%sort by first and then second column
A = sortrows(A,[1 2]);

%find each change in the first column of A
inds = find(diff(A(:,1)) > 0);

%add the last point...because find(diff) doesn't get the last point
inds(end+1) = size(A,1);

%get just those rows that meet the desired criteria
A = A(inds,:);

因此,这是通过对数据进行排序并在第一列中查找不重复的值来实现的。如果存在重复值,此代码将获取最后一个重复值。最后,由于我们通过
sortrows(A[12])
按两列进行排序,重复值的最后一个条目将具有第二列中最大的对应值。我认为这符合您的所有要求。

我不知道有任何一个电话,就像您希望的那样。但是,它可以像下面的代码那样非常紧密地完成(并且完全矢量化)

%sort by first and then second column
A = sortrows(A,[1 2]);

%find each change in the first column of A
inds = find(diff(A(:,1)) > 0);

%add the last point...because find(diff) doesn't get the last point
inds(end+1) = size(A,1);

%get just those rows that meet the desired criteria
A = A(inds,:);

因此,这是通过对数据进行排序并在第一列中查找不重复的值来实现的。如果存在重复值,此代码将获取最后一个重复值。最后,由于我们通过
sortrows(A[12])
按两列进行排序,重复值的最后一个条目将具有第二列中最大的对应值。我认为这符合您的所有要求。

我不知道有任何一个电话,就像您希望的那样。但是,它可以像下面的代码那样非常紧密地完成(并且完全矢量化)

%sort by first and then second column
A = sortrows(A,[1 2]);

%find each change in the first column of A
inds = find(diff(A(:,1)) > 0);

%add the last point...because find(diff) doesn't get the last point
inds(end+1) = size(A,1);

%get just those rows that meet the desired criteria
A = A(inds,:);

因此,这是通过对数据进行排序并在第一列中查找不重复的值来实现的。如果存在重复值,此代码将获取最后一个重复值。最后,由于我们通过
sortrows(A[12])
按两列进行排序,重复值的最后一个条目将具有第二列中最大的对应值。我认为这符合您的所有要求。

我不知道有任何一个电话,就像您希望的那样。但是,它可以像下面的代码那样非常紧密地完成(并且完全矢量化)

%sort by first and then second column
A = sortrows(A,[1 2]);

%find each change in the first column of A
inds = find(diff(A(:,1)) > 0);

%add the last point...because find(diff) doesn't get the last point
inds(end+1) = size(A,1);

%get just those rows that meet the desired criteria
A = A(inds,:);
因此,这是通过对数据进行排序并在第一列中查找不重复的值来实现的。如果存在重复值,此代码将获取最后一个重复值。最后,由于我们通过
sortrows(A[12])
按两列进行排序,重复值的最后一个条目将具有第二列中最大的对应值。我认为这符合您的所有要求。

使用和:

使用和:

使用和:

使用和:


太好了,正是我想要的。谢谢。太好了,正是我想要的。谢谢。太好了,正是我想要的。谢谢。太好了,正是我想要的。非常感谢。