How to create diagonal block matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Tommy
le 9 Avr 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 commentaires
Tommy
le 11 Avr 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{:});
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!