How can I pad zeros to each column of a matrix?
조회 수: 4 (최근 30일)
이전 댓글 표시
I am given a matrix with t rows and n columns. I want to add zeros to each column. How can I achieve this? I was thinking about the padarray-command:
X_padded = padarray(X,[10000 0]);
But I think this yields a matrix X with only zeros added to it in column n=1.
댓글 수: 0
채택된 답변
Stephen23
2016년 12월 27일
Here are two easy ways to add zeros onto a matrix:
>> mat = [1,2,3;4,5,6]
mat =
1 2 3
4 5 6
>> [mat;zeros(2,3)]
ans =
1 2 3
4 5 6
0 0 0
0 0 0
>> mat(5,1) = 0
mat =
1 2 3
4 5 6
0 0 0
0 0 0
0 0 0
댓글 수: 2
Image Analyst
2016년 12월 27일
Try getting rid of the third dimension, if you don't need or want it, like this:
x = squeeze(x);
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!