How to generate a identity matrix based on another matrix

2 views (last 30 days)
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

Stephen23
Stephen23 on 18 Feb 2015
Edited: Stephen23 on 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.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!