How do I plot rectangles with filled color on a 2D plot?

조회 수: 34 (최근 30일)
TAUFIQ SAIDIN
TAUFIQ SAIDIN 2021년 5월 17일
댓글: TAUFIQ SAIDIN 2021년 5월 17일
Hi all,
Seeking helps from esteemed Matlab users/experts.
I need help on how to plot rectangles with filled color on a cartesian coordinate (2D) plot. Please see attached figure below the expected plot I am looking forward to.
Regards,
Taufiq
  댓글 수: 3
David Fletcher
David Fletcher 2021년 5월 17일
You might want to have a look at the fill command as well - a bit more versatile
TAUFIQ SAIDIN
TAUFIQ SAIDIN 2021년 5월 17일
Thank you @David Fletcher 😊 for recommending an alternative to rectangle method, which looks me to a little bit more simple and more flexible as you said

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2021년 5월 17일
Read about fill, patch. You need to have coordinates of the vertices.
Example:
% Vertices of rectangle
P = [0 0 ;0 1; 1 1; 1 0] ;
patch(P(:,1),P(:,2),'r','EdgeColor','k')
  댓글 수: 1
TAUFIQ SAIDIN
TAUFIQ SAIDIN 2021년 5월 17일
Thank you @KSSV for recommending an alternative method to rectangle i.e. patch. As suggested by @David Fletcher earlier, now I know at least these are 3 methods I could use to accomplish my objective:
Truly appreciate it guys 😊

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by