Run a function erverytime a new Datatip is selected (Callbacks for datatips)

조회 수: 36 (최근 30일)
Philipp Schulz
Philipp Schulz 2021년 6월 17일
댓글: Adam Danz 2021년 6월 24일
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
Mario Malic
Mario Malic 2021년 6월 18일
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
Philipp Schulz 2021년 6월 22일
This is what I tried to do after understanding your first answer. I created the variable dataTips in my property.
Then I was describing the variable app.dataTips in my startup Function as:
app.dataTips = findall(groot, 'type', 'datatip'); % groot, axes handle, figure handle, any graphic object
Now my problem is to define a callback function that runs after everytime the value app.dataTips changes. This way I have the chance to save the new datatip in the end of my array of all datatips. Do you know a way to create a function as such?
This would help me out a lot

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2021년 6월 22일
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
Here's an example of using a ButtonDownFcn to create a datatip (use this only in cases where the option above is not supported).
  댓글 수: 2
Philipp Schulz
Philipp Schulz 2021년 6월 24일
Hello Adam,
thank you for this detailed answer. This helpeld me a lot solving my problem.
I have one more question. Once I enable datacursormode, my graph doesn't display datatips while hovering over them. This was working before activating datacursormode.
Is there a solution to it?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by