Arrays 删除矩阵中元素在matlab中相同的行
例如,给定一个2列矩阵。输入为:Arrays 删除矩阵中元素在matlab中相同的行,arrays,matlab,matrix,Arrays,Matlab,Matrix,例如,给定一个2列矩阵。输入为: [ 1,2; 3,4; 5,5] 预期产出为: [1,2; 3,4;] 有人知道如何做到这一点吗?非常感谢您的时间和关注。您可以使用逻辑索引: A = [1 2;3 4;5 5]; match = A(:,1) == A(:,2); // 1 where row has the same elements in both columns A(match,:) = []; // make the match columns empty 对于另一种情
[ 1,2;
3,4;
5,5]
预期产出为:
[1,2;
3,4;]
有人知道如何做到这一点吗?非常感谢您的时间和关注。您可以使用逻辑索引:
A = [1 2;3 4;5 5];
match = A(:,1) == A(:,2); // 1 where row has the same elements in both columns
A(match,:) = []; // make the match columns empty
对于另一种情况,您需要使其更通用,但对于两列和您的示例,这将起作用。您可以使用逻辑索引:
A = [1 2;3 4;5 5];
match = A(:,1) == A(:,2); // 1 where row has the same elements in both columns
A(match,:) = []; // make the match columns empty
对于另一种情况,您需要使其更通用,但对于两列和您的示例,这将起作用。您的问题表明,您的矩阵可能具有任意数量的列。在这种情况下,如果一行(a)任意两个元素相等,或(b)所有元素相等,则可能需要删除该行 一种可能的办法是:
您的问题表明您的矩阵可能有任意数量的列。在这种情况下,如果一行(a)任意两个元素相等,或(b)所有元素相等,则可能需要删除该行 一种可能的办法是:
Y =
1 2 3
Z =
1 2 3
3 4 3