Reputation: 1
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.
Upvotes: 0
Views: 231
Reputation: 1199
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);
Upvotes: 1