Error on converting datestr to datenum

12 visualizaciones (últimos 30 días)
kostas asamidis
kostas asamidis el 10 de Nov. de 2017
Respondida: Star Strider el 10 de Nov. de 2017
Here is my code :
time0=200;
formatOut = 'yyyy-MM-dd HH:mm:SS';
t{1}=datestr(now,formatOut);
for i=2:length(time0)
t0=datenum(t{i-1});
t2=(addtodate(t0,2,'second'));
t{i}=datestr(t2);
end
ch=t;
t = datetime(ch,'InputFormat','yyyy-MM-dd HH:mm:SS');
I want to simply create a data stream by adding in first time step(getting real time) 2 seconds in each time step.And then Hold all this values in a datetime format(it has to be for my needs in this format).
But when i run my script i get this error:
"Error using datetime (line 602)Unable to parse date/time text using the format 'yyyy-MM-dd HH:mm:SS'."
Is there any tip?

Respuestas (1)

Star Strider
Star Strider el 10 de Nov. de 2017
The correct format is 'yyyy-MM-dd HH:mm:ss'.
However, there is a much easier way to create your datetime array:
t0 = datetime('now');
tv = t0 + seconds(2:2:200);

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by