How to I add zeroes onto a matrix?

조회 수: 1 (최근 30일)
Sarah Nolt-Caraway
Sarah Nolt-Caraway 2021년 9월 21일
답변: Stephen23 2021년 9월 22일
So I have a matrix, that needs to be 1x52500. If it isnt, I want to pad zeroes onto the end. This is what I have, but it did not add the zeroes.
Matrix = zeros(1,52500);
if length(index) ~= length(Matrix)
padarray(index,[0 1],0,'post')
end

채택된 답변

Ryan
Ryan 2021년 9월 22일
편집: Ryan 2021년 9월 22일
I don't have the image processing toolbox so not sure how you would do it with padarray but you could also do it this way
Assuming "Matrix" is your data array to pad...
[~,X] = size(Matrix);
if X < 52500
Matrix = [Matrix,zeros(1,52500-X)]
end

추가 답변 (1개)

Stephen23
Stephen23 2021년 9월 22일
Where V is your vector:
V(end+1:52500) = 0

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by