pad matrix to a particular size
Show older comments
I have a matrix M of size m x n
m and n may or may not be equal - M can be rectangular or square matrix - where m and n are less than 150,
I wanted to resize M to 150 x 150 by padding border with zeros, such that the m x n will come in the center
M_resized = padarray(M,[x y],0,'both');
how to compute value for x and y such that i can use the same line of code for any matrix,
or is there any another way to do?
Accepted Answer
More Answers (1)
David Hill
on 13 May 2021
assuming m and n are both even.
M_resized=padarray(M,[(150-size(M,1))/2 (150-size(M,2))/2],0,'both');
1 Comment
Elysi Cochin
on 13 May 2021
Edited: Elysi Cochin
on 13 May 2021
Categories
Find more on Neuroimaging in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!