MATLAB: Fill a border of a matrix with 0’s

Image Processing Toolboxmatrix border

Lets say I have a matrix A. I want to replace all the values at the border meaning, the first row, the last row, the first column, and the last column with 0s, How do I do this

Best Answer

Try this:
grayImage(1,:) = 0;
grayImage(end,:) = 0;
grayImage(:,1) = 0;
grayImage(:,end) = 0;
Related, if you want to add a layer of 0's all the way around, you can use padarray() if you have the Image Processing Toolbox:
paddedImage = padarray(grayImage,[1 1]);
Related Question