Datetime/Duration Error: Input data must be one numeric matrix when converting from a different date/time representation.
Mostrar comentarios más antiguos
Since a previous post's solution with the same datetime error didn't work on my end, I made this post.
I am trying to combine Date and Time variables by datetime and duration them respectively from a 1454x7 table labelled "buoyF".
buoyF = renamevars(buoyF, {'Var1', 'Var2', 'Var3', 'Var4', 'Var5', 'Var6', 'Var7'}, ...
{'Date', 'Time', 'East', 'North', 'Speed', 'Water Direction', 'Temp'});
buoyF.Date = datetime(buoyF.Date, 'ConvertFrom', text, 'Format', 'dd/MM/yyyy');
buoyF.Time = duration(buoyF.Time,'ConvertFrom', text, 'Format', 'hh:mm:ss');
buoyF.datetime = buoyF.Date+buoyF.Time
3 comentarios
Steven Lord
el 6 de Oct. de 2024
What does "didn't work" mean in this context?
- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do? Be specific.
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
Leyton
el 6 de Oct. de 2024
@Steven Lord, the error message/input preprocessing in especially duration might be improved; this took a lot longer to diagnose the problem because the error messages were all about trying to convert the string representation failing whereas the underlying problem was that the inputs already were datenum and duration because the readxxx routines automagically and silently interpreted the input and returned datetime dates and duration times.
If the input types were checked first; the error could be returned of "Cannot convert Duration class variable as character input" or somesuch...or, one could even go so far as to turn the error into a warning and just return the input data.
Either way, the actual error information produced was not particularly useful in identifying the root cause.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
