removing part of a box plot

boxx = [3;7;7;3;3];
boxy = [3;3;7;7;3];
figure(1)
boxing = plot(boxx,boxy);
xlim([0 11]);
ylim([0 11]);
the code above plots a simple box
how do i remove part of the box such as removing everything above y=6?
to be clearer, to remove the top, y=6 to y=7 part of the line from the left and right lines
ie, removing the blue lines above the green line shown in the picture below
the simple method i know of is to make a new plot by slightly changing the values in the code such as below
boxx = [3;3;6;6];
boxy = [6;3;3;6];
boxing = plot(boxx,boxy);
but since i need it to be dynamic where sometimes i want it at y=5 or y=6.5 and will use the same concept with other shapes such as circulars, triangulars or 2d polygons
is there a different method or code i can use to remove the lines?

6 件のコメント

Rik
Rik 2021 年 2 月 19 日
You can't remove part of a line object, so you will have to use a similar tactic for your other shapes as well.
Adam Danz
Adam Danz 2021 年 2 月 19 日
If the box edges are always parallel to the axes, it's as easy as,
boxy(boxy>6) = 6;
Adrian Lee
Adrian Lee 2021 年 2 月 21 日
for this case it will always be parallel, but for some other cases which i will tackle in the future, mostly will not be parallel to axes or each other
Adam Danz
Adam Danz 2021 年 2 月 21 日
Then you need to rotate the vertices using a rotation matrix before applying the height cuttoff.
Adrian Lee
Adrian Lee 2021 年 2 月 21 日
ah, i see
hmm,
i would need an equation for identifying the length needed before the rotation
then use the rotation matrix for plotting a new line... or i am mistaken?
Adam Danz
Adam Danz 2021 年 2 月 21 日
No, that's not quite right.
If the edges of your rectangle are not parallel to the axes you'll need to rotate the rectangle so that it is parallel, then apply the cutoff, and then counter-rotate it back to its original orientation.

サインインしてコメントする。

回答 (0 件)

製品

リリース

R2020a

タグ

質問済み:

2021 年 2 月 19 日

コメント済み:

2021 年 2 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by