How to generate a identity matrix based on another matrix

2 visualizzazioni (ultimi 30 giorni)
Hi, all,
Here is my problem, there is a matrix [1 2 3; 2 3 4],
How to change it into the following matrix
[1 2 3 0 0 0; 0 0 0 2 3 4];
Thanks a lot.

Risposta accettata

Stephen23
Stephen23 il 18 Feb 2015
Modificato: Stephen23 il 18 Feb 2015
You can use blkdiag for this:
>> A = [1 2 3; 2 3 4];
>> B = num2cell(A,2);
>> blkdiag(B{:})
ans =
1 2 3 0 0 0
0 0 0 2 3 4
This is not an identity matrix though.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by