Error when trying to check the "Tag" of a plot
1 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!