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

 Akzeptierte Antwort

Star Strider
Star Strider am 8 Jun. 2020

0 Stimmen

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 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by