Unless you are using an older version of MATLAB, you are likely much better of using readtable to read your data into a table, converting the date text into a datetime (if necessary, depends on what version of MATLAB you're using and how the spreadsheet is set up), and plotting the vales vs. the datetimes.
Let's assume readtable gives you a table something like this:
>> t = table({'Jan-05';'Feb-05';'Mar-05'},[1;2;3],'VariableNames',{'A' 'B'})
t =
3×2 table
A B
________ _
'Jan-05' 1
'Feb-05' 2
'Mar-05' 3
Do this:
>> t.A = datetime(t.A,'InputFormat','MMM-yy')
t =
3×2 table
A B
___________ _
01-Jan-2005 1
01-Feb-2005 2
01-Mar-2005 3
>> plot(t.A,t.B)
If you need to tinker with the x axis ticks or labels, here's where to find them:
>> h = gca;
>> h.XAxis
ans =
DatetimeRuler with properties:
Limits: [01-Jan-2005 05-Mar-2005]
TickValues: [01-Jan-2005 15-Jan-2005 29-Jan-2005 12-Feb-2005 26-Feb-2005]
TickLabelFormat: 'MMM dd'
Show all properties
Best Answer