how can I print these diagonal patterns by writing a loop in a 21x21 array?

 채택된 답변

Star Strider
Star Strider 2020년 6월 8일

0 개 추천

Try this:
M = diag([ones(1,9) 0 ones(1,9)]);
M = M + fliplr(M);
M(ceil(size(M,1)/2), ceil(size(M,1)/2)) = 1;
figure
imagesc(M)
axis('image')
colormap([0 0 0; 1 1 1])
No loops necessary.
Experiment to get different results.

댓글 수: 2

Ekin Yilmaz
Ekin Yilmaz 2020년 6월 8일
Very grateful, thank you. You're my hero.
Star Strider
Star Strider 2020년 6월 8일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

질문:

2020년 6월 8일

댓글:

2020년 6월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by