Azzera filtri
Azzera filtri

use structure to draw a group of boxes

2 visualizzazioni (ultimi 30 giorni)
Nabin SUNAM
Nabin SUNAM il 17 Mar 2015
Risposto: Star Strider il 17 Mar 2015
I have drawn five boxes using rectangle function writing code for each box. This doesn't look elegant however. I'm thinking I could use structures and loop to draw these boxes. I have just started learning about structures. This one seems to out of scope of what I've learned so far. Could anyone help me out?
% Row of Boxes: Steps: 1 to 5
rectangle('Position', [1 22 20 20], 'FaceColor', [0.6 0.7 0.5], 'EdgeColor', [0.9 0.1 0.1], 'LineWidth', 1.5);
rectangle('Position', [22 22 20 20], 'FaceColor', [0.6 0.7 0.5], 'EdgeColor', [0.9 0.1 0.1], 'LineWidth', 1.5);
rectangle('Position', [43 22 20 20], 'FaceColor', [0.6 0.7 0.5],... 'EdgeColor', [0.9 0.1 0.1], 'LineWidth', 1.5);
rectangle('Position', [64 22 20 20], 'FaceColor', [0.6 0.7 0.5],... 'EdgeColor', [0.9 0.1 0.1], 'LineWidth', 1.5);
rectangle('Position', [85 22 20 20], 'FaceColor', [0.6 0.7 0.5],... 'EdgeColor', [0.9 0.1 0.1], 'LineWidth', 1.5);

Risposte (1)

Star Strider
Star Strider il 17 Mar 2015
I would just do a loop:
for k1 = 1:5
rectangle('Position', [(22*(k1-1)+2-k1) 22 20 20], 'FaceColor', [0.6 0.7 0.5], 'EdgeColor', [0.9 0.1 0.1], 'LineWidth', 1.5);
end

Community Treasure Hunt

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

Start Hunting!

Translated by