Arrange the matrix by replace a part to another part

1 view (last 30 days)
Hi
I have 4 matrices as example, I would like to arrange these matrices to be one big matrix after keep only (the beginning of rows and columns) as this example
If I have
A1=ones(12);
A2=ones(9)*2;
A3=ones(6)*3;
A4=ones(4)*4;
I would like to find the final matrix after keep only the first 3 (the beginning of rows and columns in each matrix ) , so the final matriix should be like
ATOT=
[1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 2 2 2 2 2 2 2 2 2
1 1 1 2 2 2 2 2 2 2 2 2
1 1 1 2 2 2 2 2 2 2 2 2
1 1 1 2 2 2 3 3 3 3 3 3
1 1 1 2 2 2 3 3 3 3 3 3
1 1 1 2 2 2 3 3 3 3 3 3
1 1 1 2 2 2 3 3 3 4 4 4
1 1 1 2 2 2 3 3 3 4 4 4
1 1 1 2 2 2 3 3 3 4 4 4];
please i would like to specify the number of (the beginning of rows and columns) that should keep because i have diffrent size of matrices
thank you very much
  2 Comments
Aakash Deep Chhonkar
Aakash Deep Chhonkar on 19 Jul 2021
Edited: Aakash Deep Chhonkar on 19 Jul 2021
Also, focus on which part of the matrix you want to update rather than which part you want to preserve, this will clear the picture more.

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 19 Jul 2021
Assuming your matrices are conveniently sized...
A1=ones(12);
A2=ones(9)*2;
A3=ones(6)*3;
A4=ones(3)*4;
A = A1;
A(4:end,4:end) = A2;
A(7:end,7:end) = A3;
A(10:end,10:end) = A4
Output:
A =
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 2 2 2 2 2 2 2 2 2
1 1 1 2 2 2 2 2 2 2 2 2
1 1 1 2 2 2 2 2 2 2 2 2
1 1 1 2 2 2 3 3 3 3 3 3
1 1 1 2 2 2 3 3 3 3 3 3
1 1 1 2 2 2 3 3 3 3 3 3
1 1 1 2 2 2 3 3 3 4 4 4
1 1 1 2 2 2 3 3 3 4 4 4
1 1 1 2 2 2 3 3 3 4 4 4

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!