Re-indexing matrix which corresponds to mesh

4 views (last 30 days)
Hello
I'm wondering if anyone can help me. I'm trying to re-index two matrixes. I have selected a sub-sample of data and I need them to be re-numbered to 1:N. There is a corresponding matrix which is an Mx3 matrix which makes up the triangles.
I need to re-number the first matrax and then apply that re-numbered matrix to the list of triangles. This cannot be done by simple indexing because the numbers in the original matrix are obviously changed so they do not correspond with values in the 2nd matrix.
I'm not sure if I've explained that well but here is an example of the matrices I currently have.
I would also like to point out that those are just a sample number, the nodes may not necessarily match up below but they do in my matrices.
Cheers :)
Nodes:
3772
3947
3948
3949
4144
4145
4146
4147
4148
4149
Tri:
3771 3772 3603
3604 3603 3772
3773 3604 3772
3771 3946 3947
3948 3771 3947
3771 3948 3772
3772 3948 3949
3772 3949 3950
3772 3950 3773
3947 3946 4143
  7 Comments
KSSV
KSSV on 12 Jun 2017
What you gave is the exact subset?
Meghan Rochford
Meghan Rochford on 12 Jun 2017
The exact subset is:
Node=
3772
3947
3948
3949
4144
4145
4146
4147
4148
4149
4334
4335
4336
4337
4338
4339
4501
4502
4503
4504
4505
4506
4507
4690
3771
3604
3773
3771
3771
3950
4143
4333
4500
4500
4688
4689
4689
4689
3603
3604
3946
3771
3950
3946
4150
4333
4499
4500
4688
4689
4876
3603
3950
3773
4143
4143
4150
4333
4499
Triangles=
3771 3772 3603
3604 3603 3772
3773 3604 3772
3771 3946 3947
3948 3771 3947
3771 3948 3772
3772 3948 3949
3772 3949 3950
3772 3950 3773
3947 3946 4143
4144 3947 4143
3947 4144 4145
4145 4146 3947
3948 3947 4146
4146 4147 3948
3949 3948 4147
4147 4148 3949
3949 4148 4149
4149 4150 3949
3950 3949 4150
4143 4333 4144
4334 4144 4333
4334 4335 4144
4335 4145 4144
4335 4336 4145
4337 4145 4336
4337 4146 4145
4337 4338 4146
4147 4146 4338
4338 4339 4147
4148 4147 4339
4333 4499 4334
4500 4334 4499
4334 4500 4501
4334 4501 4335
4335 4501 4502
4502 4336 4335
4336 4502 4503
4503 4504 4336
4504 4505 4336
4337 4336 4505
4506 4337 4505
4506 4338 4337
4506 4507 4338
4507 4339 4338
4500 4688 4501
4688 4689 4501
4689 4502 4501
4689 4690 4502
4690 4503 4502
4689 4876 4690

Sign in to comment.

Accepted Answer

KSSV
KSSV on 12 Jun 2017
Edited: KSSV on 12 Jun 2017
Let nodes and tri be your Nodes and Triangles.
[val,idx] = unique(nodes) ;
nodes_1 = nodes ;
tri_1 = tri ;
for i = 1:length(val)
nodes_1(nodes==val(i))=i ;
tri_1(tri==val(i)) = i ;
end
tri_1 and nodes_1 are the Nodes and Triangles re-indexed to 1:N.

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 12 Jun 2017
Edited: Andrei Bobrov on 12 Jun 2017
Node_out = (1:numel(Node))';
[~,Triangles_out] = ismember(Triangles,Node);
or
[v,~,Node_out] = unique(Node,'stable');
Triangles_out = ismember(Triangles,v);
  2 Comments
Meghan Rochford
Meghan Rochford on 12 Jun 2017
I don't need to know if they belong to the same matrix. I know they do. I want to re-number the nodes and then correspondingly re-number the node ID in the triangle mesh.
Sterling Baird
Sterling Baird on 7 May 2021
Triangles_out is your new, renumbered triangulation. This is great, thank you! Neat application of ismember()

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!