将单位矩阵插入到较大的空矩阵维中(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)] );更多推荐
发布评论