Effacer les filtres
Effacer les filtres

can you fix this matrix?

2 vues (au cours des 30 derniers jours)
Tia
Tia le 20 Avr 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 commentaire
Walter Roberson
Walter Roberson le 20 Avr 2013
Why are you re-assigning m(1,1) during each iteration of the "for" loop?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Avr 2013
m = -ones(4);
m(1,1) = 1;
  1 commentaire
Tia
Tia le 21 Avr 2013
it works.. thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by