Borrar filtros
Borrar filtros

use structure to draw a group of boxes

2 visualizaciones (últimos 30 días)
Nabin SUNAM
Nabin SUNAM el 17 de Mzo. de 2015
Respondida: Star Strider el 17 de Mzo. de 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);

Respuestas (1)

Star Strider
Star Strider el 17 de Mzo. de 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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by