Using nested for loop to alter a previous matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to define a 5x5 matrix with all zeros, then use a nested for loop to alter that matrix to look like
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171369/image.png)
How do I go about doing this? I understand that I need to have some sort of counter to go up as each element increases down the column.
댓글 수: 0
답변 (1개)
Rik
2018년 3월 18일
Is this homework? If not, why not avoid a loop:
A =1:25;
A2=reshape(A,5,5);
댓글 수: 2
Image Analyst
2018년 3월 18일
Since it's homework, which means you're not allowed to turn in Birdman's code as your own (lest you get caught "cheating"), then you should have tagged it as homework in advance. But it should be easy for you to do something very similar so that it's your own work you're turning in.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!