Reputation: 59
I am trying to plot a bunch of data that are 2 min averages and I want to have the label on the xaxis show day/month hour:mins. I can get some dates to show up on the xaxis but there are a few problems:
below is a sample. any help would be greatly welcome.
%make date vec
ds = {'28/01/2000 11:52:00';'28/01/2000 11:54:00';'28/01/2000 11:56:00'};
x = datenum(ds,'dd/mm/yyyy HH:MM:SS')
y = [1,2,3]; %data
plot (x,y,'x')
%define start and end date for xAxis
startDate = x(1)
endDate = x(end)
xdata = linspace(startDate,endDate,5)
set(gca,'XTick',xdata)
datetick('x','dd/yy HH:MM')
Upvotes: 2
Views: 5696
Reputation: 1
Here is what worked for me to get ticks every minute
step=2.5/3600; % minute
debut = (floor(pts_dthgps(1)/step))*step;
fin = (floor(pts_dthgps(sz)/step))*step;
figure(2);
h=plot(pts_dthgps, pts_vitgps);
set(gca, 'XTick', [debut:step:fin]);
datetick('x','HH:MM','keeplimits','keepticks');
Upvotes: 0
Reputation: 11168
Add the option keepticks
to the datetick
call. Fixed things up here on my R2012a:
datetick('x','dd/yy HH:MM','keepticks')
Source: this and datetick doc
Upvotes: 1
Reputation: 45752
One solution is instead of using datetick()
set the ticklabels your self. So replace your last line of code with these two lines:
dsdata = datestr(xdata, 'dd/yy HH:MM');
set(gca,'XTickLabel',dsdata);
Upvotes: 0