Question about ordering and sorting matrices

1 vue (au cours des 30 derniers jours)
Brian
Brian le 5 Déc 2012
Hello, thanks for looking at this,
I have a peculiar matrix that I would like to order and sort. The matrix itself is imported form a geometry file exported from Ansys, and it looks like:
18f 1b6 368 1 db3
18f 252 1b6 1 e60
1b6 252 368 1 da7
18f 368 252 1 e3e
53 194 3e 2 1d0
53 29c 194 2 1100
194 29c 3e 2 884
53 3e 29c 2 71d
26f 2fa 2d1 3 426
26f 2ba 2fa 3 1b0
2fa 2ba 2d1 3 847
26f 2d1 2ba 3 10fd
34f 1e7 27b 4 925
34f 31d 1e7 4 5bc
1e7 31d 27b 4 92c
34f 27b 31d 4 2a8
222 21e 2b3 5 4ce
222 3a7 21e 5 1127
Now, here is a bit of information on this matrix. The first three column entries are hexadecimal point indices, and they form a triangle. Meaning, in the first row: point 18f is connected to 1b6 and is connected to 368 (all hex), and this forms a triangle.
The last two column entries are tetrahedra indexes, and are important in the fact that for each tetrahedra, there are at least 3 rows. The reason there are at least three is there are four triangles for each tetrahedra, however, some of the triangles are surface elements (which I don't need). There are at least three of each tetrahedra index, but the cumulative 3 indexes exist in the thid and forth column, index 1 is special because all four indexes exist in column four. This doesn't always happen, this is especially evident as you progress through the face matrix, since Ansys doesn't want to export duplicate entries.
Now, what I think I can do in order to have a single tetradedra index column that is ordered by 1 to N, and has at least 3 of each index (i.e. 1 1 1, 2 2 2, etc) is concatanate the fourth and fifth columns, as that would make a single column where every tetrahedra index is listed at least three times, and then I can check the first three columns and see if any of the rows exist for the given ordered tetrahedra index, and then re-create a longer row-wise but shorter column-wise (by 1 row) face matrix where its ordered by the last tetrahedra index column.
Any advice on how I can do this/is this even the best method to use you can give me would be appreciated! Thanks!

Réponses (1)

Sean de Wolski
Sean de Wolski le 5 Déc 2012
Well first, you'll have to use hex2dec to get the hexadecimals to decimals.
Second, can you make a smaller example of what you expect for outputs. E.g.:
18f 1b6 368 1 db3
Should become what?
doc hex2dec
doc sort
to get you started
  3 commentaires
John Petersen
John Petersen le 5 Déc 2012
I don't see a duplication in the 2nd matrix that you're talking about.
Brian
Brian le 5 Déc 2012
What I meant by this was I wanted to sort from 1 to N in column 4, and line 1 would be repeated for tetrahedra 1 and 256. So I would just about duplicate the number of rows.
I think I managed to do this by:
facemx1 = faceMx(:,1:4);
facemx2 = faceMx(:,1:3);
facemx2 = [facemx2 faceMx(:,5)];
completeFaceMx = [facemx1;facemx2];
sortrows(completeFaceMx,4);
clear facemx1 facemx2
So, basically, I create two new matrices with one of the tetrahedra indexes (col4 or 5), I concatenate the matrices, the sort by the forth column. It's not exactly what I envisioned, and it wastes memory (esp for larger files), but it works.
Thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by