Fill a border of a matrix with 0's
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jhangir
el 6 de Nov. de 2013
Editada: Image Analyst
el 6 de Nov. de 2013
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
0 comentarios
Respuesta aceptada
Image Analyst
el 6 de Nov. de 2013
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]);
2 comentarios
Image Analyst
el 6 de Nov. de 2013
Editada: Image Analyst
el 6 de Nov. de 2013
Like I showed you "end" is a convenient way to get the last index of any dimension without actually having to use the size() function to determine what index value that would be.
And you don't need the commas in your code. For readability I're recommend putting them on separate lines.
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!