Easy way to change callback function

4 visualizaciones (últimos 30 días)
David Teitge
David Teitge el 11 de Jun. de 2019
Comentada: Walter Roberson el 11 de Jun. de 2019
I am trying to change the callback function on a bar graph to show pertinent information about the event when a user clicks on one of the bars. I have stumbled through changing the callback function to do this, but I have to manually choose my callback function from the figure window. I would like to use some function in the script so that MATLAB knows to use my own callback function instead of its default. Is there a one line solution to this or do I need to dive deeper into callback functions in MATLAB?

Respuestas (2)

Steven Lord
Steven Lord el 11 de Jun. de 2019
It sounds like you want to customize the text that appears when you have data cursors enabled, or that's one way you could achieve your goal. If so use the datacursormode function to retrieve the data cursor mode object for your figure and set its UpdateFcn property. There's an example on the datacursormode documentation page that customizes the cursor for a line plot created with plot and you should be able to adapt that example for use with a bar plot.

Walter Roberson
Walter Roberson el 11 de Jun. de 2019
h = bar(randi(10,5,3));
set(h, 'ButtonDownFcn', @(varargin) disp('I''m hit!'))
  2 comentarios
David Teitge
David Teitge el 11 de Jun. de 2019
So I can reference my callback function with your code, but one of the inputs to the function is the event object and I do not know what this is or how to get it.
Walter Roberson
Walter Roberson el 11 de Jun. de 2019
set(h, 'ButtonDownFcn', @(hObject, event, varargin) disp(event))

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by