Not able to convert array to datetime, help, please!
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 15 Jul. 2020
Not without a sample test case that illustrates the problem can run here -- the above code snippet by itself works in a script the same as the command line
>> testit
fechadef =
5×1 datetime array
NaT
26-Jun-2020
NaT
NaT
NaT
>>
>> type testit
fechaDef = [...
{'9999-99-99'}
{'6/26/2020' }
{'9999-99-99'}
{'9999-99-99'}
{'9999-99-99'}];
fechadef=datetime(fechaDef,'InputFormat','MM/dd/yyyy')
>>
There's something else gone wrong in the script before there that is the cause of the problem but we can't see or run the script to be able to tell what that might be.
Pull out the pieces and make test code by adding more and more until you find the culprit...
DVR
am 15 Jul. 2020
Walter Roberson
am 15 Jul. 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 :(
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!