How can I view the formatted date string(DATESTR) while using Date Cursor for a plot containing date strings on MATLAB 8.1(R2013a)?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 18 Oct 2013
Réponse apportée : MathWorks Support Team
le 21 Fév 2014
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?
Réponse acceptée
MathWorks Support Team
le 18 Oct 2013
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!