How can I pad zeros to each column of a matrix?
20 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Stephen23
on 27 Dec 2016
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 Comments
Image Analyst
on 27 Dec 2016
Try getting rid of the third dimension, if you don't need or want it, like this:
x = squeeze(x);
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!