Filter löschen
Filter löschen

Matrix manipulation problem under MATLAB

1 Ansicht (letzte 30 Tage)
dakhli mohamed
dakhli mohamed am 21 Nov. 2018
Beantwortet: Guillaume am 21 Nov. 2018
I want to put a matrix A in another matrix B
example
A= 0 2 9
5 7 3
4 6 1
B= 0 2 9 0 0 0
5 7 3 0 0 0
4 6 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
and a C matrix in another place
C= 1 2 3
4 5 6
7 8 9
B= 0 2 9 0 0 0
5 7 3 0 0 0
4 6 1 0 0 0
0 0 0 1 2 3
0 0 0 4 5 6
0 0 0 7 8 9

Akzeptierte Antwort

Adam
Adam am 21 Nov. 2018
Bearbeitet: Adam am 21 Nov. 2018
A = [0 2 9; 5 7 3; 4 6 1];
C = [1 2 3; 4 5 6; 7 8 9];
B = zeros(6);
B(1:3,1:3) = A;
B(4:6,4:6) = C;
  2 Kommentare
dakhli mohamed
dakhli mohamed am 21 Nov. 2018
I want to redo the same work but with a matrix of size 284 * 284
what should I do
Adam
Adam am 21 Nov. 2018
Just extend it in the obvious way based on whatever you want to insert.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Guillaume
Guillaume am 21 Nov. 2018
Possibly, you're looking for blkdiag:
A = [0 2 9; 5 7 3; 4 6 1];
C = [1 2 3; 4 5 6; 7 8 9];
B = blkdiag(A, C)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by