use structure to draw a group of boxes
1 view (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Star Strider
on 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
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!