How can I view the formatted date string(DATESTR) while using Date Cursor for a plot containing date strings on MATLAB 8.1(R2013a)?
조회 수: 5 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2013년 10월 18일
답변: MathWorks Support Team
2014년 2월 21일
When I plot a date with some data, it seems I have to pass in DATENUM instead of DATESTR to the plot function. Thus, when I click on the data point, I see a DATENUM value, not a straight forward DATESTR that I can understand. Is there a way in which I can display the readable DATESTR format?
채택된 답변
MathWorks Support Team
2013년 10월 18일
A simple way to achieve this is to change the display format in the UpdateFcn of the Data Cursor.
Consider the following command which plots the date value on the x-axis:
plot(datenum(dateVal), yValue);
Create a Data Cursor object as follows:
dcm_obj = datacursormode(gcf);
You need to assign a callback function to UpdateFcn. Let's call this MYFUNCTION. MYFUNCTION specifies how the data cursor tooltip should display the coordinate values.
set(dcm_obj, 'UpdateFcn',@myfunction);
In MYFUNCTION specifu the display format as DATESTR for the appropriate coordinate(in this case, x-coordinate.)
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: ', datestr(pos(1))],... % Notice the X coordinate value has been changed to DATESTR
['Y: ',num2str(pos(2),4)]};
% 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),4)];
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!