如何在矩阵中找到唯一的行,每行中没有元素顺序? [英] How can I find unique rows in a matrix, with no element order within each row?

查看:18
本文介绍了如何在矩阵中找到唯一的行,每行中没有元素顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 n 行和 4 列的数组.该行的四个条目中的每一个都是一个整数,即,

I have an array comprising n rows and 4 colums. Each of the four entries on the row is an integer, i.e.,

X = [
       111 112 432   2
         6   9 115 111
       112 432 111   2

    ]; 

每一行代表一个四面体的顶点.这些顶点没有方向性,因此在上述情况下,由 X(1,:) 和 X(3,:) 表示的四面体是等价的.

Each row represents the vertices of a tetrahedron. These vertices have no directionality thus, in the case above, the tetrahedra represented by X(1,:) and X(3,:) are equivalent.

我想从 X 中删除重复的四面体,但不太清楚如何将顺序独立性合并到我的代码中.

I wish to remove duplicate tetrahedra from X, but can't quite figure how to incorporate the order independence into my code.

我尝试了 UNIQUE() 函数,但它返回一个 (nx1) 唯一整数数组,即,

I tried the UNIQUE() function but this returns a (nx1) array of unique integers, i.e.,

Y = UNIQUE(X);

Y = [
     2
     6
     9
     111
     112
     115
     432
    ]

有人对完成这项任务的合理有效方法有什么建议吗?

Anyone have any suggestions for a reasonably efficient way to complete this task?

谢谢,:-)

推荐答案

首先,对矩阵的行进行排序以获得四面体的规范"表示:

First, sort the rows of your matrix to arrive at a "canonical" representation for the tetrahedra:

X = sort(X, 2);

然后,使用 unique 和可选的 'rows' 参数来查找唯一的行:

Then, use unique with the optional 'rows' argument to find unique rows:

Y = unique(X, 'rows');

这篇关于如何在矩阵中找到唯一的行,每行中没有元素顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆