Insert rows and columns of zeros between every row column

后端 未结 1 2013
一个人的身影
一个人的身影 2021-01-15 16:26

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

相关标签:
1条回答
  • 2021-01-15 17:14

    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.

    Create a new matrix with the dimensions 2Mx2N

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

    (assuming that A is your original matrix). Using

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

    should result in the correct new matrix.

    0 讨论(0)
提交回复
热议问题