在每行列之间插入零行和零列 [英] Insert rows and columns of zeros between every row column

查看:176
本文介绍了在每行列之间插入零行和零列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个MxN矩阵,我该如何在Matlab中原始矩阵的每隔一列/每行之后添加(而不是替换)一行零和一列零? 实际上,结果将是2Mx2N.

If i have a MxN matrix, how do i add(not replace) a row of zeros and a column of zeros after every other column/row in the original matrix in matlab? Effectively the result would be 2Mx2N.

推荐答案

您可以按照以下方式进行操作.不要添加新的行和列,而是创建一个空矩阵并填充原始矩阵中的元素.

You can do it in the following way. Do not add the new rows and columns but create an empty matrix and fill the elements from the original matrix.

创建一个尺寸为2Mx2N

 B = zeros(2*size(A));

(假设A是您的原始矩阵).使用

(assuming that A is your original matrix). Using

 B(1:2:end,1:2:end) = A;

应该生成正确的新矩阵.

should result in the correct new matrix.

这篇关于在每行列之间插入零行和零列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆