How to combine matrices with different size but preserve elements with same value?

조회 수: 4 (최근 30일)
I have 4 columns of data which are FEM element number that share the same node (the elements are tetrahedron, hence 4 nodes) with one specific element, I want to merge them into one column so that when I select one element I can get all the elements that are connected with selected element.
for example
A= [1; 5; 8; 9], B=[1; 2; 4; 5; 7; 9]
and I want to get C=[1; 2; 4; 5; 7; 8; 9]
Is this possible?

채택된 답변

Jan
Jan 2021년 6월 9일
Do you mean union?
A = [1; 5; 8; 9];
B = [1; 2; 4; 5; 7; 9];
C = union(A, B)
C = 7×1
1 2 4 5 7 8 9

추가 답변 (2개)

Fangjun Jiang
Fangjun Jiang 2021년 6월 9일
unique([A;B])?

Steven Lord
Steven Lord 2021년 6월 9일
None of A, B, or C have four columns like you stated you had.
You didn't indicate how you generated C from A and B, but one way to do so:
A= [1; 5; 8; 9];
B=[1; 2; 4; 5; 7; 9];
C = union(A, B)
C = 7×1
1 2 4 5 7 8 9
whos A B C % 1 column each
Name Size Bytes Class Attributes A 4x1 32 double B 6x1 48 double C 7x1 56 double
  댓글 수: 1
Steven Lai
Steven Lai 2021년 6월 9일
A B and C are just example, I just want to make sure I can simplify my problem enough.
Union is perfect, even though I need to do it three times because it can't have more than 2 argument in it.
Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by