Run a function erverytime a new Datatip is selected (Callbacks for datatips)
Afficher commentaires plus anciens
Hello Matlab Community,
I would highly appreciate your help. I have the folowing problem:
I am creating a GUI, which is able to work with Datatips interactivly.
My goal is to create a function that run everytime a new datatip is selected. I want to do many things with that function, for exampel saving the datatips to an array or showing the last selected datapoint in the label below.
I am basicially talking about a callback for datatipselected.
That's why I am looking for a simple way to solve this. A pseudo code for this would be:
datatipselected = listener('selectingdatatips')
set(datatipselected, @run)
function run
% run code
end

4 commentaires
Mario Malic
le 17 Juin 2021
Not sure if I've understood correctly, so I'm posting this as a comment.
When the datatip is created, it's contained in the Children property of the graphic primitive such as line.
If you want to execute your callback when a new datatip is displayed in all graphic objects or a specific one.
dataTips = findall(groot, 'type', 'datatip'); % groot, axes handle, figure handle, any graphic object
You can use numel to get number of datatips, and if it changes, you can run your function.
Philipp Schulz
le 17 Juin 2021
Mario Malic
le 18 Juin 2021
See Interactivity sectíon https://ch.mathworks.com/help/matlab/ref/matlab.ui.figureappd-properties.html ButtonDownFcn probably should be the way to go. You should see examples with callbacks on uifigures/uiaxes first as it is not simple at first.
What do you mean by variable? I think you'll have to make your variable a property of the app so you can access it inside callback.
Philipp Schulz
le 22 Juin 2021
Réponses (1)
Adam Danz
le 22 Juin 2021
1 vote
You can set the UpdateFcn of datacursormode. The function will execute every time a datatip is added. You can do anything you want within that function but you'll either need to reconstruct the original datatip or add new lines to the datatip.
Here are two demos that use custom update functions; you can run them to see how they work.
Here are demos that use custom update function to add a row of data to the datatip
- Add C value to surf object
- Add C value to scatter
- Add C value to pcolor
- Add a name to each line
- Add a date to each point
- Add parameter values to curves
- Add a 3rd value to X,Y info
Here's an example of using a ButtonDownFcn to create a datatip (use this only in cases where the option above is not supported).
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!