Converting Excel dates into MATLAB while accounting for Leap Days

Hi,
So I have dates in an excel sheet and depending upon the year it can either be 365x1 or 366x1 for a leap year. Is there anyway I can keep the cell array in 366x1 without leaving an NAN at day 60. I tried that previously leaving a NAN at day 60 feb 29 for all non-leap years and when I tried using the datenum function to convert the dates to serial dates I would get the error
Error using datenum (line 181)DATENUM failed.
Caused by:
Error using datevec (line 212)
Failed to lookup month of year.
Here is the code that I have for reading the documents and creating the variables for year 2010, there are 3 other copies of this code for years 2011-2013 etc
[~,~,TData] = xlsread('Project.xlsx','Year 2010','A2:L367');
Dates2010=[TData(:,2)];
Weeks2010=[TData(:,3)];
TotalEvents2010 = [TData(:,4)];
WeekdayEvents2010= [TData(:,5)];
WeekendEvents2010= [TData(:,6)];
HolidayEvents2010= [TData(:,7)];
SpinalEvents2010= [TData(:,8)];
HeadBackEvents2010= [TData(:,9)];
ChestRegionAssociatedOrgans2010= [TData(:,10)];
AbdominalRegionPelvis2010= [TData(:,11)];
Others2010=[TData(:,12)];
a1=cellfun(@datenum,Dates2010);
b1= cell2mat(Weeks2010);
c1= cell2mat(TotalEvents2010);
d1= cell2mat(WeekdayEvents2010);
e1= cell2mat(WeekendEvents2010);
f1= cell2mat(HolidayEvents2010);
g1= cell2mat(SpinalEvents2010);
h1= cell2mat(HeadBackEvents2010);
i1= cell2mat(ChestRegionAssociatedOrgans2010);
j1= cell2mat(AbdominalRegionPelvis2010);
k1= cell2mat(Others2010);
I need the a1 variable to be the same size as all the other variables so that I can plot it on the x-axis and plot c1-k1 on the y-axis. Keep in mind the end goal would be to plot all dates from 2010-2013 on the x-axis and c1-k1 for 2010-2013 on the y axis.
Regards

Respuestas (1)

Peter Perkins
Peter Perkins el 28 de Mzo. de 2018
your example is not very clear to me. My advice is to use readtable, not xlsread, and use datetimes, not datenums. Beyond that, I think you need to provide a short clear example of what you have and what you want.

Categorías

Preguntada:

el 27 de Mzo. de 2018

Editada:

el 28 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by