Diagonal Pattern by writing loops?

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

 Accepted Answer

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 Comments

Very grateful, thank you. You're my hero.
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!