Adding zeros to matrix

조회 수: 2 (최근 30일)
Anjali Sharma
Anjali Sharma 2020년 8월 5일
댓글: Anjali Sharma 2020년 8월 5일
I have to do image processing. I have one data with 100 x 100 matrix and another with 300 x 300 matrix. I want to add zeros to 100 x100 matrix to equalize it like 300 x300 but zeros to be added after 100 x 100 equally and not in particular end.

채택된 답변

Bruno Luong
Bruno Luong 2020년 8월 5일
% Replace this with your image
Image100 = peaks(100)+10;
%Centering padding in 4 sides
PadImage300 = zeros(300,300,size(Image100,3),class(Image100));
PadImage300(101:200,101:200,:) = Image100;
imagesc(PadImage300)

추가 답변 (1개)

KSSV
KSSV 2020년 8월 5일
편집: KSSV 2020년 8월 5일
Let A be your 100*100 matrix.
B = zeros(300) ;
B(1:100,1:100) = A ;
  댓글 수: 3
KSSV
KSSV 2020년 8월 5일
A = rand(2) ;
[m,n] = size(A) ;
B = zeros(3*m,3*n) ;
B((m+1):2*m,(n+1):2*n) = A ;
Also read about padarray
Anjali Sharma
Anjali Sharma 2020년 8월 5일
Yes this worked..!!!
Thank you.
Unfortunately I dont have Image toolbox so cant use padarray otherwise it could be easy.

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by