How to generate a identity matrix based on another matrix

1 回表示 (過去 30 日間)
valley
valley 2015 年 2 月 18 日
コメント済み: valley 2015 年 2 月 18 日
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.

採用された回答

Stephen23
Stephen23 2015 年 2 月 18 日
編集済み: Stephen23 2015 年 2 月 18 日
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.
  1 件のコメント
valley
valley 2015 年 2 月 18 日
thx a lot, this answer is perfect.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by