passing variables into custom datacursor in a GUI

5 visualizaciones (últimos 30 días)
HpW
HpW el 27 de Nov. de 2017
Comentada: HpW el 28 de Nov. de 2017
Hello. I have a GUI and I would like to enable a custom datacursor. I have used the following code to setup the dataursor in the GUI to be enabled for all of the axes in the GUI:
dcm = datacursormode;
set(dcm, 'update', {@display_datacursor});
I then have a separate file called display_datacursor.m which contains the following code:
function output_txt = display_datacursor(obj,event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
step = 2;
pos = get(event_obj,'Position');
I = get(event_obj, 'DataIndex');
T = (get(event_obj, 'DataIndex')-1)*step;
output_txt = {['Sample: ',num2str(pos(1),4)],...
['Time (ms): ',num2str((pos(1)-1)*step)],...
['Amplitude (mV): ',num2str(pos(2),4)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt = {['X (mV): ',num2str(pos(1),4)],...
['Y (mV): ',num2str(pos(2),4)],...
['Z (mV): ',num2str(pos(3),4)],...
['Time (ms): ',num2str(T)]};
end
This allows different data cursor text for the various 2D and 3D graphs in the GUI. This works fine (although it seems to make everything run very slow....if anyone has any idea why this is the case would be appreciated), but I would like to be able to dynamically change the value of 'step'. Ive tried using handles, but it doesnt work. Ive tried passing in arguments like this:
set(dcm, 'update', {@display_datacursor, step});
but this also doesnt work....
How can i pass data into display_datacursor.m?
thanks!
  1 comentario
Walter Roberson
Walter Roberson el 27 de Nov. de 2017
Minor optimization:
In the step
T = (get(event_obj, 'DataIndex')-1)*step;
you already have get(event_obj, 'DataIndex') stored in I, so you can use
T = (I - 1) * step

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Nov. de 2017
set(dcm, 'update', {@display_datacursor, step});
with
function output_txt = display_datacursor(obj, event_obj, step)
and do not assign to step in the function.

Más respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by