将单位矩阵插入到较大的空矩阵维中(Insert an identity matrix into a larger dimension of null matrix)

编程入门 行业动态 更新时间:2024-10-13 02:19:51
将单位矩阵插入到较大的空矩阵维中(Insert an identity matrix into a larger dimension of null matrix)

假设我有一个单位矩阵。

I=eye(3)

这将产生

I = [1 0 0 0 1 0 0 0 1]

现在我想将I插入到(5X5)空矩阵中,这样我的结果就是

N = [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1]

我怎么能有效地实现这一目标。谢谢你

Suppose i have an identity matrix .

I=eye(3)

which will produce

I = [1 0 0 0 1 0 0 0 1]

Now i want to insert I into a (5X5) null matrix such that my result will be

N = [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1]

How could i achieve this efficiently .Thanks in advace

最满意答案

或者,

m = 5; n = 3; a = diag( [zeros(1, m-n), ones(1,n)] );

Alternatively,

m = 5; n = 3; a = diag( [zeros(1, m-n), ones(1,n)] );

更多推荐

本文发布于:2023-08-05 20:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437957.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵   较大   单位   Insert   identity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!