Search code examples
matlabcell

Error converting cell to date using datenum() in MATLAB


I have a very large <1165900 x 1 cell> 'a' that I want to convert into datenum. I've done this somehow before but it has stopped working for me. Instead, I get the following error now:

Error using datenum (line 179)
DATENUM failed.

Caused by:
    Error using dtstr2dtnummx
    Failed on converting date string to date number.

I've just written this as the code:

b = datenum(a, 'dd.mm.yyyy HH.MM.SS.FFF');

Does anyone know what I've done wrong?


Solution

  • The syntax into datenum is correct, are you certain that a is formatted correctly?

    Here is some code I used to verify the syntax into datenum was correct:

    %define format string
    fmt = 'dd.mm.yy HH.MM.SS';
    
    %create dateString using current time
    dStr = datestr(now, fmt);
    
    %convert num to string with datenum
    dNum = dateNum(dStr, fmt);