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

2 visualizzazioni (ultimi 30 giorni)
Jason
Jason il 20 Gen 2020
Commentato: Jason il 21 Gen 2020
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 Commenti
dpb
dpb il 20 Gen 2020
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by