How to Plot a Date on the X Axis using xlsread?

2 views (last 30 days)
I've read in an excel file using:
>>[num,txt,raw] = xlsread(FilePath, sheet, range);
having my code in previous steps specify the FilePath, sheet, and range; they read in to the "raw" array exactly as I want them to.
What I want to do is plot a few of the "columns" from the raw array. Specifically, I want the first column to be the x-axis, with 3 other columns as lines in the y-axis. But I want the x-axis to be in some sort or date format- preferably MM-YYYY. When I plot it by using the plot toolbar on the top of the Matlab program, it gives me this code:
>> plot(cell2mat(raw(:,[17,19,end])),'DisplayName','cell2mat(raw(:,[17,19,end]))')
which plots the data exactly as I want it to, but the x-axis is not the date- it's just a number from 1-365 (I guess just the row number).
Any help or advice with this?

Accepted Answer

dpb
dpb on 19 Mar 2014
Select the column that contains the date and convert to Matlab datenum. Then use datetick to format the x-axis in time units desired.
See
doc datenum
doc datetick
and links under Excel importing for converting Excel dates to Matlab datenums if they're serial dates instead of character strings.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!