pad matrix to a particular size
Ältere Kommentare anzeigen
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?
Akzeptierte Antwort
Weitere Antworten (1)
David Hill
am 13 Mai 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 Kommentar
Elysi Cochin
am 13 Mai 2021
Bearbeitet: Elysi Cochin
am 13 Mai 2021
Kategorien
Mehr zu Neuroimaging finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!