Creation of multiple rectangles

18 ビュー (過去 30 日間)
Gereon Ridder
Gereon Ridder 2020 年 2 月 5 日
回答済み: Sai Bhargav Avula 2020 年 2 月 20 日
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)];

採用された回答

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by