How do I combine four 3x3 matrices into a 6x6 matrix?

조회 수: 11 (최근 30일)
Rakshith M
Rakshith M 2022년 3월 10일
댓글: Rakshith M 2022년 3월 13일
Suppose I have the matrices
A=[1 1 1
1 1 1
1 1 1]
B=[2 2 2
2 2 2
2 2 2]
C=[3 3 3
3 3 3
3 3 3]
D=[4 4 4;
4 4 4;
4 4 4]
I need the combined matrix to be,
New=[ 1 1 1 2 2 2
1 1 1 2 2 2
1 1 1 2 2 2
3 3 3 4 4 4
3 3 3 4 4 4
3 3 3 4 4 4]
I could write a loop and combine it as such but I would likle to know if there are any functions that could do the same!!

채택된 답변

Davide Masiello
Davide Masiello 2022년 3월 10일
편집: Davide Masiello 2022년 3월 10일
If it's really only 4 matrixes, then I would just write
New = [[A,B];[C,D]];
If the code needs to be expanded for a larger number of matrixes then it may be convenient to use a loop, but you should specify how those matrixes must be arranged to form the new one.
  댓글 수: 4
Stephen23
Stephen23 2022년 3월 10일
"When I suggested a loop I thought of something like concatenating a large number of matrixes"
Using a loop to concatenate (and enlarge) an array on each loop iteration is very inefficient. Much better approaches would be to use indexing to allocate the data to a preallocated array, or use a comma-separated list with CAT or [].
Rakshith M
Rakshith M 2022년 3월 13일
Thanks for the help!!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by