Not able to convert array to datetime, help, please!

1 visualización (últimos 30 días)
DVR
DVR el 15 de Jul. de 2020
Comentada: Walter Roberson el 15 de Jul. de 2020
I have this table imported from a csv file after using
datos = readtable(filename)
fechaDef = datos{:,{'FECHA_DEF'}}
fechaDef =
{'9999-99-99'}
{'6/26/2020' }
{'9999-99-99'}
{'9999-99-99'}
{'9999-99-99'}
....
And i want to convert it to datetime format, i want to have the '9999-99-99' as NaT
What I'm doing is
fechaDef = datos{:,{'FECHA_DEF'}} %NaT if not a Datetime
fechaDef = table2array(fechaDef);
fechaDef = datetime(fechaDef,'InputFormat','MM/dd/yyyy')
I can write those commands and execute them successully at the command window.
But when writing them in a script i get the following error:
Can you tell me what am I doing wrong?
Thanks in advance!
  3 comentarios
DVR
DVR el 15 de Jul. de 2020
Thanks for your fast answer dpb.
Attached you can find my script, in fact i'm getting a warning but dont know if that is related with the error.
Also attached is the .csv file i'm using.
Walter Roberson
Walter Roberson el 15 de Jul. de 2020
data = cat(1, image_patches,labels);
That code is overwriting all of data each iteration.
It looks to me as if data will not be a vector, but I do not seem to be able to locate any hellopatches() function so I cannot tell what shape it will be. As you are not doing imresize() I also cannot be sure that all of the images are the same size, so I cannot be sure that data will be the same size for each iteration. Under the circumstances you should be considering saving into a cell array.
Note: please do not post the same query multiple times. I found at least 9 copies of your query :(

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 15 de Jul. de 2020
fechaDef = ...
[{'9999-99-99'};
{'6/26/2020' };
{'9999-99-99'};
{'9999-99-99'};
{'9999-99-99'}]
fechaDef2 = replace(fechaDef, '9999-99-99', 'NaT')
dt = datetime(fechaDef2, 'InputFormat', 'MM/dd/yyyy')
  2 comentarios
DVR
DVR el 15 de Jul. de 2020
Absolutetly right, replace was the function i was missing, thank you Steven!
dpb
dpb el 15 de Jul. de 2020
So what's the difference that DVR was finding, Steven?
Why isn't datetime returning NaT on its own (presuming it really is failing)?
That seems like retrogression if is newly-introduced behavior since R2019b which works as expected here, anyways.
I was more expecting it to barf on the "MM" format string with a '6/26/2020' datestring but it seems ok with that now. My recollection is that would fail in earlier releases but I didn't go back to try to test.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by