How to create diagonal block matrix
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
raina RAJ
am 9 Apr. 2020
Kommentiert: raina RAJ
am 11 Apr. 2020

I am trying to write code for the above matrix. I am very new to MATLAB programming. If anyone can help me in someway, It will be very nice. Thank you.
0 Kommentare
Akzeptierte Antwort
Tommy
am 9 Apr. 2020
How about this?
>> blkdiag(reshape(1:9,3,3)', [1,2;4,5], [1,2;4,5], 1, 1)
ans =
1 2 3 0 0 0 0 0 0
4 5 6 0 0 0 0 0 0
7 8 9 0 0 0 0 0 0
0 0 0 1 2 0 0 0 0
0 0 0 4 5 0 0 0 0
0 0 0 0 0 1 2 0 0
0 0 0 0 0 4 5 0 0
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1
8 Kommentare
Tommy
am 11 Apr. 2020
Thank you, that was just what I needed! Please, let me know if the following works:
c = input('c? ');
g = input('g? ');
M = cell(c+1,1);
a_t = min([1:c+1;repmat(c-g,1,c+1)]);
for i = 1:c+1
MCell = repmat({sym([char(i-1+'A') '%d%d'], [c+2-i c+2-i])}, 1, a_t(i));
M{i} = blkdiag(MCell{:});
end
B=blkdiag(M{:});
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!