Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
834 views
in Technique[技术] by (71.8m points)

arrays - How can I find unique rows in a matrix, with no element order within each row?

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

    ]; 

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.

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

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?

Thanks, S :-)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

X = sort(X, 2);

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

Y = unique(X, 'rows');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...