Hello, i need your help to understand how patch works. I have made a 2D plot in matlab and i would like to add some patches to it. I use the following commands
xpatch=[340.04 340.07;340.04 340.07]; % create x axis patch area
ypatch=[0 1600;0 1600]; % create y axis patch area
patch(xpatch,ypatch,'r');
my problem is that even if the patch object has been created in the plot brower of the figure window, it isn't visible in my figure. I would appreciate any help
Thank you

 채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 29일

0 개 추천

Do not use 2D arrays for the patch coordinates: patch() wants vector lists of coordinates for each patch.
xpatch = [340.04 340.07 340.07 340.04 340.04];
ypatch = [0 0 1600 1600 0];
patch(xpatch,ypatch,'r')
The point order is important here, as are the seeming duplications.

댓글 수: 4

Andrew Newell
Andrew Newell 2012년 2월 29일
The fifth elements in xpatch and ypatch aren't needed.
Andrew Newell
Andrew Newell 2012년 2월 29일
The reason for the point order is that you must give the points in the order you are traversing the patch, e.g, [xpatch(1) ypatch(1)] to [xpatch(2) ypatch(2)] ...
Walter Roberson
Walter Roberson 2012년 2월 29일
I prefer not to count upon patch() automatically closing the patch.
Kostas
Kostas 2012년 2월 29일
Thanks a lot for the help, it worked fine when i created the same plot from the beginning

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

추가 답변 (1개)

Kostas
Kostas 2012년 2월 29일

0 개 추천

Thanks for your answers, i have made the proposed alterations but i still get the same result, as can be seen in the following image

댓글 수: 1

Jonathan Sullivan
Jonathan Sullivan 2012년 2월 29일
It works for me. Make sure you use the hold on command before trying to pot anything else on top.

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

카테고리

태그

Community Treasure Hunt

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

Start Hunting!

Translated by