问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/41997908/insert-rows-and-columns-of-zeros-between-every-row-column