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 Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by