Creation of multiple rectangles

30 views (last 30 days)
Hallo,
i have got a question to my code. This function creates only 10 rectangles, so i would like to make it more efficient, that this is not only working for 10. Furthermore, i would like to change the way it is stored in the array. As you can see my array is reallly long, and only for 10 rectangles.
Any help would be nice.
x and y are both 10x1 coordinates of another figure, the rectangles are on the edge of this figure.
function S = sBox(x,y)
%sBox creates the secondary box out of coordinates
S1 = [x(1) y(1); x(2) y(1); x(2) y(2); x(1) y(2); x(1) y(1)];
S2 = [x(2) y(2); x(3) y(2); x(3) y(3); x(2) y(3); x(2) y(2)];
S3 = [x(3) y(3); x(4) y(3); x(4) y(4); x(3) y(4); x(3) y(3)];
S4 = [x(4) y(4); x(5) y(4); x(5) y(5); x(4) y(5); x(4) y(4)];
S5 = [x(5) y(5); x(6) y(5); x(6) y(6); x(5) y(6); x(5) y(5)];
S6 = [x(6) y(6); x(7) y(6); x(7) y(7); x(6) y(7); x(6) y(6)];
S7 = [x(7) y(7); x(8) y(7); x(8) y(8); x(7) y(8); x(7) y(7)];
S8 = [x(8) y(8); x(9) y(8); x(9) y(9); x(8) y(9); x(8) y(8)];
S9 = [x(9) y(9); x(10) y(9); x(10) y(10); x(9) y(10); x(9) y(9)];
S10= [x(10) y(10); x(1) y(10); x(1) y(1); x(10) y(1); x(10) y(10)];
S = [x(1) y(1)
x(2) y(1)
x(2) y(2)
x(1) y(2)
x(1) y(1)
x(2) y(2)
x(3) y(2)
x(3) y(3)
x(2) y(3)
x(2) y(2)
x(3) y(3)
x(4) y(3)
x(4) y(4)
x(3) y(4)
x(3) y(3)
x(4) y(4)
x(5) y(4)
x(5) y(5)
x(4) y(5)
x(4) y(4)
x(5) y(5)
x(6) y(5)
x(6) y(6)
x(5) y(6)
x(5) y(5)
x(6) y(6)
x(7) y(6)
x(7) y(7)
x(6) y(7)
x(6) y(6)
x(7) y(7)
x(8) y(7)
x(8) y(8)
x(7) y(8)
x(7) y(7)
x(8) y(8)
x(9) y(8)
x(9) y(9)
x(8) y(9)
x(8) y(8)
x(9) y(9)
x(10) y(9)
x(10) y(10)
x(9) y(10)
x(9) y(9)
x(10) y(10)
x(1) y(10)
x(1) y(1)
x(10) y(1)
x(10) y(10)];

Accepted Answer

Sai Bhargav Avula
Sai Bhargav Avula on 20 Feb 2020
Hi,
You can use patch function for this purpose.
Oleg in the following answer explains how that can be achieved.
Hope this helps!

More Answers (0)

Categories

Find more on Line Plots 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!