Borrar filtros
Borrar filtros

can you fix this matrix?

2 visualizaciones (últimos 30 días)
Tia
Tia el 20 de Abr. de 2013
m=ones(4);
x=-1;
for i=1:3;
m(1,1)=-x;
m(1,1+i)=x;
m(2:end,1:end)=x;
end
i want to make it's shorter and easier. can you fix it?
example:
[1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1]
i want the output will be
[1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1]
thank you very much
  1 comentario
Walter Roberson
Walter Roberson el 20 de Abr. de 2013
Why are you re-assigning m(1,1) during each iteration of the "for" loop?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Abr. de 2013
m = -ones(4);
m(1,1) = 1;
  1 comentario
Tia
Tia el 21 de Abr. de 2013
it works.. thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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