passing variables into custom datacursor in a GUI

3 ビュー (過去 30 日間)
HpW
HpW 2017 年 11 月 27 日
コメント済み: HpW 2017 年 11 月 28 日
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
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
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.
  1 件のコメント
HpW
HpW 2017 年 11 月 28 日
thank you! worked perfectly!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by