why textscan can't parse the time like this
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lang
el 8 de Abr. de 2025
tunit='days since 2024-10-31 18:00:00';
rn=textscan(tunit,'%s since %{yyyy-MM-dd HH:mm:ss}D',1);
0 comentarios
Respuesta aceptada
Stephen23
el 8 de Abr. de 2025
Editada: Stephen23
el 8 de Abr. de 2025
"why textscan can't parse the time like this"
Because you have a delimiter right in the middle of your datestamp. Clearly that will not work: TEXTSCAN always splits at delimiters (because that is the meaning of a delimiter). Also note that you explicitly wrote delimiters in the format string, but with TEXTSCAN you specify the delimiter (or use the default) and then do NOT write it in the format string.
You can parse the date & time as DATETIME & DURATION objects and then add them together:
tunit = 'days since 2024-10-31 18:00:00';
rn = textscan(tunit,'%ssince%{y-M-d}D%{hh:mm:ss}T')
dt = rn{2}+rn{3};
dt.Format = 'yyyy-MM-dd HH:mm:ss'
Or using the automagic DATETIME & DURATION format detection:
rn = textscan(tunit,'%ssince%D%T');
dt = rn{2}+rn{3};
dt.Format = 'yyyy-MM-dd HH:mm:ss'
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files 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!