pad matrix to a particular size
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (1)
David Hill
el 13 de Mayo de 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 comentario
Elysi Cochin
el 13 de Mayo de 2021
Editada: Elysi Cochin
el 13 de Mayo de 2021
Categorías
Más información sobre Neuroimaging en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!