Filter löschen
Filter löschen

use structure to draw a group of boxes

2 Ansichten (letzte 30 Tage)
Nabin SUNAM
Nabin SUNAM am 17 Mär. 2015
Beantwortet: Star Strider am 17 Mär. 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);

Antworten (1)

Star Strider
Star Strider am 17 Mär. 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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by