Increase matrix size, with the first matrix a the center of the new matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
suppose to have a matrix (2000x2000) now i want to copy it in a bigger matrix (4000x4000 for example), with the original matrix at the center of the second matrix, and the other values set to 0. How can I do?
I have done it with for loop, but it is slow
댓글 수: 0
답변 (1개)
Turlough Hughes
2020년 10월 12일
편집: Turlough Hughes
2020년 10월 12일
There is a function made specifically for this called padarray, try the following example:
A = rand(2000);
B = padarray(A,[1000 1000]);
댓글 수: 2
Turlough Hughes
2020년 10월 12일
Creating an array B=zeros(4000) is unnecessary because you are not using it in the next step. You can simply write:
C = padarray(A,[1000 1000]);
to get what you are looking for.
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!