MATLAB: How to manually change plot x-axis to months

xticklabels

I have been trying to manually change the xtick label to show months instead of the array that i'm plotting, however it only shows a portion of the string and I can't get to show the months from Jan-Dec.
month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
h(6) = figure;
plot(Day1Sum)
hold on
plot (Day2Sum,'r')
% xlim ([1 hrsyr])
legend ('Load', 'Load with DR')
ylabel ('Load (MWh)')
xticklabels(month)

Best Answer

You need to pass a cell array to xticklabels instead of a string. You build a cell array with {} instead of []. For example
month = {"Jan","Feb","Mar",...}
Second, it is better to work with datetime format, as manipulating your ticklabels makes for buggy code. Will gladly show you how, if you provide your x-data.
Related Question