Can you detect when a title is added to a plot?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a GUI where a single figure has multiple pannels. Graphs can be added to these panels at any unknown time by a user. I want to populate a popup menu with the titles of graphs (axes) as they are added to these panels by the user. User population is to work the same as adding a plot to a standard figure in that after creating the figure, the code really has no idea at what point the user will add the plot and the title so there is no post add title point at which to pull the title. It would instead need to be able to react to the title being added. I have tried manualy creating a blank axes on the panel for which the user will plot to next so that the next plot is directed there and attached a propertly listerer to the string property of the title object of the axes. This should work except that it doesnt due to new plots to an existing axes result in the old axes title being deleted in the background with no clear way to find the handle to the new title. Any ideas on a good way to do this?
7 Kommentare
Weitere Antworten (1)
Sean de Wolski
am 27 Feb. 2019
If the axes already exists, this seems to work
ax = axes
addlistener(ax.Title,'String','PostSet',@(~, ~)disp('hi'))
title('Hello World')
Now just change the listener callback to fire an update of your listbox.
7 Kommentare
Jan
am 28 Feb. 2019
@Dan: I've done equivalent things in the Matlab level by creating an 'Enable'='inactive' element and let its ButtonDownFcn (not the Callback) trigger the automatic collection of data. Then instead of a popup menu I show a UIContextMenu at the same position, because I can set its Visible status dynamically to let it appear as if it was an activated popup menu. Not nice to write, but looks fine and I have all functionality, where it is needed. The user can do, whatever he wants, because the pseudo-popup keeps the power of finding, what it is needed.
Of course I do like the idea of letting new objects send a message which allows to identify them. But as long as Matlab is not completely object oriented and the plot command is inherited from the current figure automatically, such that you can define figure depended modifications directly, I prefer the active collection instead of a message passing.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!