Command 'plot3' clears functions which were added when an axes is created in GUIDE. Why?

조회 수: 1 (최근 30일)
Hi all,
I created an axes - My_Axes (using GUIDE but I think it doesn't matter) - and specified a 'ButtonDownFcn' to treat mouse clicks on the created graph. However, when I plot something on this axes using the the funcition 'plot3' the axes field 'ButtonDownFcn' is cleared! Of course, nothing happens when later I click with the mouse on the graph. Strangely, this is not the case when I create a graph using 'plot' (I didn't check all the other plotting functions). Why? Is this the way Matlab is suppose to treat axes?
Thanks,
Alon

채택된 답변

Steven Lord
Steven Lord 2017년 1월 24일
I don't believe this is a bug. When you call a high-level plotting function like plot or plot3, MATLAB needs to know how to configure the axes into which the graphics object will be plotted. By default, "new plots added to the axes clear existing plots and reset all axes properties." [That's not technically true; the Position and Units properties keep their values.]
To avoid this behavior, use the hold function to change the behavior from the default behavior I described above, use a lower-level plotting function like line, or manually change the axes NextPlot property (which is similar or equivalent to what hold does.)
I'm guessing you didn't see this behavior when you called plot because you also used hold or because you set the ButtonDownFcn property after plotting.
  댓글 수: 1
Alon Rozen
Alon Rozen 2017년 1월 24일
Hi,
Thanks! I understand the design issue here. I will accept it as is. The simplest solution is to use a command which re-assigned the desired 'ButtonDownFcn' to the axes just after completing the drowning. This is how I overcome this problem anyway.
Thanks again,
Alon

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

추가 답변 (1개)

Jan
Jan 2017년 1월 24일
편집: Jan 2017년 1월 24일
I assume this is a bug. Which Matlab version an OS are you using?
Does it help to set the 'NextPlot' property of the axes object to 'add'? This is equivalent to hold on, but then an automatic replacement of the axes' content is disabled.
  댓글 수: 1
Alon Rozen
Alon Rozen 2017년 1월 24일
Hi,
Thanks!
As I commented on the next answer - if I have to bother anyway, I will just re-assigned the function after completing the drawing. I do need the automatic replacement from time to time.

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by