MATLAB: Convert day year hour data series with missing data to a serial number

date time series serial number

I have a year of data from "01/01/2003 00:00" to "2003/12/31 23:59" with some days/hous missing from the data series. I think to convert these dates/times to serial numbers I have to use the datenum. To convert each one of these numbers I understand that I have to do: datenum(2003,1,1,0,0,0) which gives ans =
731582.00
This is fine for one number but how I can convert the whole series? thanks, Katerina

Best Answer

  • f = fopen('dates1.txt');
    c = textscan(f,'%s %s','collectoutput',1);
    fclose(f);
    out = datenum(strcat(c{1}(:,1),{'_'},c{1}(:,2)),'dd/mm/yyyy_HH:MM');
    or
    f = fopen('dates1.txt');
    c = textscan(f,'%s','delimiter','\n');
    fclose(f);
    out = datenum(c{1},'dd/mm/yyyy HH:MM')