MATLAB: Importing excel file to matlab without losing date format

load excel

Hi, I'm wondering if anyone can help me, I have spent all day trying to load some data into matlab. I finally managed to do it by convering it to a .txt file but my date variable comes out as a NaT or as a number that doesn't equate to any of my data.
My excel file has three columns without headers in this format:
10.12.19 10.37.00 5
Does this make sense to anyone? I would really really appreciate it if someone has any ideas please. Thank you

Best Answer

Hi Rosanna, If your column data is in the following format ''Years.Months.Days Hours.Minutes.Seconds Data'', then the following code will work. I have created a xlsx file with data as you descrived above. At the end you can save date-time with your data column.
clear all
% Reading data from excel file
[a b]=xlsread('yourdata_according_to_question.xlsx')
% Reading Year, Month, Day
[y, m, d] = datevec(b(:,1),'dd.mm.yy')
% Reading only HOURS, Minutes and Seconds
[yyyy, mm, dd, HH, MM, SS] = datevec(b(:,2),'HH.MM.SS')
% Converting to Year, Month, Day, HOURS, Minutes and Seconds to charectors
y=num2str(y);
m=num2str(m);
d=num2str(d);
HH=num2str(HH);
MM=num2str(MM);
SS=num2str(SS);
% Adding all charector into single line
ymd=strcat(y,'-',m,'-',d);
hms=strcat(HH,':',MM,':',SS);
alltime=strcat(ymd,{' '},hms);
% Converting to datevec or datenum
alltime_dnum=datevec(alltime)
alltime_dvec=datenum(alltime_dnum)