Create zeros in matrix size, but not 1. column and row, or last column and row

1 visualización (últimos 30 días)
Hi
I am trying to make a matrix where the middle has to be changed into zeros, f. ex. with magic(4)
v=magic(4)
v(2,2)=0; v(2,3)=0; v(3,2)=0; v(3,3)=0;
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Here i want the 11, 10, 7 and 6 to be zeros. But need it to be done in random size matrix.
Pretty new in the whole matlab world.
Anyone whom can help?
  3 comentarios
Andrew Reibold
Andrew Reibold el 15 de Ag. de 2013
(5,5) seems like it would be the middle of that..
Anders
Anders el 15 de Ag. de 2013
What I mean, is that everything else than first and last row + first and last column. Hope this will clear things out.

Iniciar sesión para comentar.

Respuesta aceptada

Roger Stafford
Roger Stafford el 15 de Ag. de 2013
v(2:3,2:3) = 0;
Note: This method only works for rectangular regions. For other shapes you need to use linear indexing.
  5 comentarios
Image Analyst
Image Analyst el 15 de Ag. de 2013
That's what Roger's code
v(2:end-1,2:end-1) = 0;
does, so you should be all set.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by