Making odd rows equal to zero in a 3x3 Matrix
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!