Making odd rows equal to zero in a 3x3 Matrix
Afficher commentaires plus anciens
Hi, I'm trying to make the rows equal to zero in a 3x3 matrix, but I don't get the result I need. Here
is my code:
>> M=magic(3)
M =
8 1 6
3 5 7
4 9 2
>> M(1:2:end)=0
M =
0 1 0
3 0 7
0 9 0
I found that using the following code I get the answer
>> M=magic(3);M(1:2:end,1:end)=0
M =
0 0 0
3 5 7
0 0 0
Could someone explain why the first code does not produce the correct result?
thanks
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!