- 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 ビュー (過去 30 日間)
古いコメントを表示
Riccardo Tronconi
2021 年 6 月 10 日
コメント済み: Riccardo Tronconi
2021 年 6 月 10 日
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 件のコメント
採用された回答
Walter Roberson
2021 年 6 月 10 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!