How to get a custom data cursor with datetime axis?

조회 수: 14 (최근 30일)
Adhi Goel
Adhi Goel 2020년 4월 23일
댓글: William 2022년 1월 31일
Hello,
I am trying to modify my data cursor when plotting with a datetime axis. However, when I apply a custom function to a datacursor's updatefcn, the variable retreived for position doesn't reflect the axis position in datetime format:
My current code is from the older non-Tex callbacks:
function output_txt = myfunction(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).
pos = get(event_obj,'Position');
output_txt = {['X: ',num2str(pos(1),10)],...
['Y: ',num2str(pos(2),10)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),10)];
end
The values for event_obj.Position(1) = 5.3139 which I do not know how to convert to datetime. I've tried the approach from this answer and then converted my axis formatting using the datetick function but the ticks do not adjust accordingly when zoomed. I would like to have a datatimeRuler with a callback function on the cursor.
Thanks in advance.

채택된 답변

Adhi Goel
Adhi Goel 2020년 4월 23일
To anyone else with this question, it can be solved using the num2ruler function. i.e., for the x-axis:
num2ruler(pos(1),event_obj.Target.Parent.XAxis)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by