Error when trying to check the "Tag" of a plot

조회 수: 2 (최근 30일)
Jason
Jason 2020년 1월 20일
댓글: Jason 2020년 1월 21일
I have plotted some data on a UIAxes and I need to determine if the user has mouse clicked on this UIAxes, rather than 4 other UIAxes I have on my GUI.
After reading this https://uk.mathworks.com/matlabcentral/answers/458264-using-windowbuttondownfcn-in-app-designer, I have followed some advice to Tag the plot.
plot(app.UIAxes, ydata, 'Tag', 'allData');
Then in my figureWindowButtonDown callback to do this:
function figure1WindowButtonDown(app, event)
if isequal(event.Source.CurrentObject.Tag,'allData')
%..do some stuff
end
end
But Im getting the following error:
Unrecognized method, property, or field 'Tag' for class 'matlab.graphics.GraphicsPlaceholder'.
if isequal(event.Source.CurrentObject.Tag,'allData')
Error while evaluating Figure WindowButtonDownFcn
  댓글 수: 2
dpb
dpb 2020년 1월 20일
You left out some important stuff from the example it appears...the comments and the if are informative:
%Create if statement that determines if the user clicked on the
%line of the top UIAxes. If they didn't, do nothing
if ~isempty(event.Source.CurrentObject) && isequal(event.Source.CurrentObject.Tag,'allData')
...
end
NB: they test to ensure a not-empty object and then that the comment notes must have clicked on a line...I don't do GUIs so I "don't know anything" really about writing GUI callbacks, but you'll need to ensure it is a line object that does have a .Tag property if there's anything else on the figure the user could possibly select.
The possibility the click didn't actually select an object is taken care of by the test for ~isempty; you got something else above that I'm not at all certain what the .GraphicsPlaceHolder is, but it isn't a line and doesn't have a .Tag property.
Jason
Jason 2020년 1월 21일
Thanks

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by