passing variables into custom datacursor in a GUI
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2017-11-27
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
采纳的回答
Walter Roberson
2017-11-27
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!