Problems with converting date strings to date numbers

Dear all!
Any pointers as to what might be going wrong here would be much appreciated:
Error using dtstr2dtvecmx Failed on converting date string to date number.
Error in datevec (line 117) y = dtstr2dtvecmx(t,icu_dtformat);
Error in day (line 39) c = datevec(d(:),f);
I'm using Matlab 2015b (but have same error on 2013a). I should also have all the required toolboxes installed. And copying the function datenum into the folder doesn't solve the problem either.
I'm not sure where this is going wrong.
Many thanks for your help, Alex

4 comentarios

Stephen23
Stephen23 el 9 de Dic. de 2015
Editada: Stephen23 el 9 de Dic. de 2015
In order for us to be able to replicate this behavior we need to have the exact code that you are using and some sample data that causes this error. In particular this means showing us the values of the variables d and f.
To get those values you will find the dbstop if error command very useful.
I see. I have tried to debug this further. I'm not sure I can provide you with values for d and f at the moment.
What I have done is to copy-paste datenum into folder with the code. This is given me the following:
*K>> forecastcombinationmasterfile_excerpt('10/09/2015') Error using datenum (line 179) DATENUM failed.
Error in year (line 31) d = datenum(d,f);
Error in forecastcombinationmasterfile_excerpt (line 10) cyear=year(cdate,'dd/mm/yyyy');
Caused by: Error: File: cnv2icudf.m Line: 1 Column: 25 The input character is not valid in MATLAB statements or expressions.
179 throw(newExc);*
I'm attaching the m.file datenum I have used for this as well.
I also attach the masterfile which is bascially just reading in the data (don't think there are any issues here).
dpb
dpb el 9 de Dic. de 2015
" I'm not sure I can provide you with values for d and f"
Why not? What prevents you from doing as Stephen suggests and displaying the values for the function when it errors?
"What I have done is to copy-paste datenum into folder with the code."
There's no advantage in doing such things; there's a serious disadvantage in that one can thereby accidentally damage the distributed code by accidentally overwriting the original or somesuch.
Again, show us the data and the actual code line used to execute the call; the error indicates there's an issue there in that the input string has an invalid character so there's a good chance your assumption the read is ok isn't...
Stephen23
Stephen23 el 9 de Dic. de 2015
Editada: Stephen23 el 9 de Dic. de 2015
Copying datenum serves no obvious purpose, and could even cause major problems. Many inbuilt (and even third-party) MATLAB functions utilize sub-functions located in private directories that are only accessible to the function in its original location. By moving such a function you run the risk of making it useless because it can no longer access those sub-functions.

Iniciar sesión para comentar.

Respuestas (1)

Usually this type of error appears when one of your input datestrings does not match the input format you specified. For example:
datenum('01/ab/2015', 'mm/dd/yyyy')
Error using datenum (line 178)
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed on converting date string to date number.
If your dataset is small enough, you may be able to find the culprit by just scanning manually. Otherwise, you may need to loop through your data in smaller chunks and see where the problem is. Unfortunately, datenum takes an all-or-nothing approach... if a single point is mis-formatted, it will fail.

Categorías

Etiquetas

Preguntada:

el 9 de Dic. de 2015

Editada:

el 9 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by