필터 지우기
필터 지우기

How can I pad zeros to each column of a matrix?

조회 수: 20 (최근 30일)
Luki
Luki 2016년 12월 27일
댓글: Image Analyst 2016년 12월 27일
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.

채택된 답변

Stephen23
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
Luki
Luki 2016년 12월 27일
allright, thx! There's one problem:
size(x) = 10000 1 41
so, I could do:
x_zeros = [x,1,zeros(100,41)]
But I'd rather get rid of the third dimension of x (the 1 depicted in size(x)). I know it's not a real 3rd dimension, because the "depth" of the matrix is just 1. But every other assignment in my code will only use two indices (for columns and rows). For x as it is right now, however, I need three indices. Can I delete that additional dimension?
Image Analyst
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개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by