How to generate a identity matrix based on another matrix

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.

 Accepted Answer

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.

More Answers (0)

Categories

Asked:

on 18 Feb 2015

Commented:

on 18 Feb 2015

Community Treasure Hunt

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

Start Hunting!