フィルターのクリア

Making rectangle with different colors

4 ビュー (過去 30 日間)
Sivert van Mourik
Sivert van Mourik 2018 年 4 月 18 日
コメント済み: Sivert van Mourik 2018 年 4 月 18 日
How do I make rectangles using matrices where all the sides in the rectangles have different colours? Should I use the line-function or does it work with the rectangle-function?

採用された回答

Stephen23
Stephen23 2018 年 4 月 18 日
編集済み: Stephen23 2018 年 4 月 18 日

The function rectangle only accepts one face color and one edge color, so it cannot be used for plotting multiple edge colors. But it is easy to use patch, which allows a lot more control over the colors, including each edge having a different color:

>> X = [0,1,1,0];
>> Y = [0,0,2,2];
>> C = [1,0,0;0,1,0;0,0,1;1,1,0];
>> patch(X,Y,'FaceVertexCData',C,'EdgeColor','flat','FaceColor','none','LineWidth',2)
>> set(gca,'visible', 'off');

giving:

  3 件のコメント
Stephen23
Stephen23 2018 年 4 月 18 日
編集済み: Stephen23 2018 年 4 月 18 日
@Sivert van Mourik: it worked for me. Please show the exact code that you tried.
Sivert van Mourik
Sivert van Mourik 2018 年 4 月 18 日
I used the exact same code as the one you commented, but I managed to make the rectangle I wanted after making a few changes to your code, so there's no worries. Thanks, by the way :)

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

その他の回答 (1 件)

KSSV
KSSV 2018 年 4 月 18 日
P = [0 0 ;
      1 0 ;
     1 1 ;
      0 1 ;
      0 0] ;
    figure
    hold on
    plot(P(1:2,1),P(1:2,2),'r') 
    plot(P(2:3,1),P(2:3,2),'b') 
    plot(P(3:4,1),P(3:4,2),'g') 
    plot(P(4:5,1),P(4:5,2),'y') 
  1 件のコメント
Sivert van Mourik
Sivert van Mourik 2018 年 4 月 18 日
What if I want to make a rectangle from two matrices, x and y, where I for example want to make a rectangle with lower left corner in (x(1,35),y(160,1)) and upper right corner in (x(1,70),y(170,1))?

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

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by