MATLAB: Adjust intervals of x-axis in the plot!

plot

Hey all,
I have SI and Date which I want to plot them. The Date is in a monthly format from 1989 to 2018 (360 months). I haven't any idea why the x interval divided into 5 years by Matlab:
But I want to set it in the monthly format.
Also, any idea how to get rid of the green line? I don't want it and I don't know why it is showing today? Yesterday I haven't this problem (the green line didn't show yesterday)
Any advice highly appreciated.
%plot vector
plot(Date,SI, 'linewidth',1.5)
xlabel('time step')
%Modify "time step"
ylabel('Precipitation')

Best Answer

You can directly set the tick locations with the xticks function. Since your variable is already a datetime (and not datenum), you don't need the datetick function.
S=load('Date.mat');
Date=S.Date;
S=load('SI.mat');
SI=S.SI;
%since the last 11 columns of SI are empty, let's remove them
SI=SI(:,1);
f=figure(1);clf(f)
plot(Date,SI, 'linewidth',1.5)
xlabel('time step')
ylabel('Standardized Precipitation Index')
xticks(Date(1:12:end))
ax=gca;
set(ax,'XTickLabelRotation',45)