简体   繁体   中英

Matlab Plot Date and Time Stamp

How can I add a date and time stamp to a matlab plot? I can't find how to anywhere. My assignment asks for the date/time to be on the plot, but not as part of the axes. Instead it must simply appear on the graph.

As David suggest, use text(...). To get the current time, convert it to a string and put it at an arbitrary position as you wish, see the example below:

dateTime = now;
dateTimeStamp = datestr(dateTime, 'dd-mmm-yyyy HH:MM:SS');
plot(peaks)
pos = [25, -6]; % Position for the stamp
text(pos(1), pos(2), dateTimeStamp, 'VerticalAlignment',...
'bottom', 'HorizontalAlignment', 'center', 'fontsize', 10);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM