Handling external variables when redefining the text displayed by the data cursor

1 view (last 30 days)
Hello everyone,
I would like to customize a matlab example defined to modify the text defined by the data cursor. The purpose is to make the data cursor dispay information that differs from its position.
The original scritp mainly looks like: fig= figure; dcm_obj = datacursormode(fig); set(dcm_obj,'UpdateFcn',@myupdatefcn)
My point is that I want to add input to the function handled by @myupdatefcn but I do not know how to call this input within the set command. Maybe it is trivial and I do not have the right keywords to check. Does someone have an idea? Many thanks in advance

Answers (1)

Jordy Jose
Jordy Jose on 31 Jan 2018
hi Isabelle,
You may pass additional arguments like this:
val = 10;
set(dcm_obj,'UpdateFcn', {@myupdatefcn, val});
For more details regarding callback definitions, please refer to the link below:
https://www.mathworks.com/help/matlab/creating_plots/callback-definition.html
The function definition for myupdatefcn will look something like this:
function out = myupdatefcn(src, evt, val)
%your code here: val will be equal to 10
end

Community Treasure Hunt

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

Start Hunting!