- Do not use a variable named duration if you can avoid it; it confuses people compared to the dataclass duration
- Do not store duration objects inside datetime objects
- The duration() equivalent of NaT is duration(nan,nan,nan) or any duration(nan,0,0) or any combination of 3 values in which at least one of them is nan.
Unexpected issue with datetime
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Riccardo Tronconi
am 10 Jun. 2021
Kommentiert: Riccardo Tronconi
am 10 Jun. 2021
Hi guys! I have this error Right hand side of an assignment must be a datetime array or text representing dates and time related to:
report12{c,3} = duration;
where
duration = end_time - start_time;
At first these entities where initialized to:
report12.B3 = NaT(height(B),1,'Format', 'HH:mm:ss.SSSSSSSSS' );
duration= NaT(height(B),1,'Format', 'HH:mm:ss.SSSSSSSSS' );
start_time = NaT;
end_time = NaT;
At the same time this works:
report12{c,1} = start_time;
Of course, these values are not null when I subtract and assign them.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 10 Jun. 2021
duration= NaT(height(B),1,'Format', 'HH:mm:ss.SSSSSSSSS' );
No matter what you name the variable, NaT creates a datetime object.
duration = end_time - start_time;
That would replace the variable named duration with a duration object .
Right hand side of an assignment must be a datetime array or text representing dates and time related to:
report12{c,3} = duration;
You failed to tell us that report12 is a table() object and that you initialized the third column of it as a datetime object. Then report12{c,3} as the destination of the assignment would be trying to store the value in the variable named duration with the duration object that is created by subtracting two datetime objects. But datetime objects can only have datetime objects stored in them.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!