필터 지우기
필터 지우기

convert 16X16 to 256X256

조회 수: 1 (최근 30일)
buddy
buddy 2011년 3월 4일
i have a 16X16 matrix.. i have to add it to a 256X256 matrix.. can anyone help me how to make this 16X16 matrix into 256X256 filling the remaining with zeros?? thank u in advance..

채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 4일
B = zeros(256,256);
B(1:size(A,1),1:size(A,2)) = A; %upper left
B(end-size(A,1)+1:end, 1:size(A,2)) = A; %lower left
With obvious generalizations to upper right and lower right
c = floor((size(B)-size(A))/2);
B(c(1)+1:c(1)+size(A,1), c(2)+1:c(2)+size(A,2)) = A; %center
The centering algorithm biases towards the upper left if the sizes are not both even or not both odd.
  댓글 수: 1
Jan
Jan 2011년 3월 4일
Exhaustive answer. +1

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

추가 답변 (1개)

Jan
Jan 2011년 3월 4일
Another method:
A = rand(16, 16);
A(256, 256) = 0;
The other zeros are created automatically. Walter's method is more powerful, because this one inserts the zeros on the right bottom only.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by