Datetime arithmetic in simulink

Hello, is it possible to do datetime arithmetic in simulink? Eventually, the code may be autogenerated to C++.
for example, in matlab i would do:
dt0 = datetime([year month day hour min sec])
increment = 0.5 % seconds
dt1 = dt + seconds(increment);

回答 (1 件)

Michael
Michael 2023 年 8 月 25 日

0 投票

You can do some arithmetics with datetime data type. For your example it is possible to add a duration to a datetime.
dt0 = datetime([2023 8 25 11 47 3]) % a point in time
dt0 = datetime
25-Aug-2023 11:47:03
increment = duration(0,0,5) % a duration of 5 seconds
increment = duration
00:00:05
dt1 = dt0 + increment % a 5 seconds later point in time
dt1 = datetime
25-Aug-2023 11:47:08

4 件のコメント

MP
MP 2023 年 8 月 25 日
編集済み: MP 2023 年 8 月 25 日
Is there a built in block that does this for simulink or using the matlab user defined function block? I believe your answer using duration may be the same as what i had in the original post if the seconds function is a duration type.
Michael
Michael 2023 年 8 月 25 日
In general a Simulink block is generating a signal (in case of of a source block) or manipulating a signal using block parameters or other signals. datetime or duration are no valid data types for signals. Or what is your intention to deal with those data types in Simulink?
MP
MP 2023 年 8 月 25 日
I need to compute UTC time to feed into a simulink aerospace toolbox block over the course of a simulation.
I suppose i can use the julian date conversion block and first convert to julian date which would give a double-type and increment that value.
Michael
Michael 2023 年 8 月 25 日
I am not familar with the Aerospace Blockset but according to documentation the Julian date conversion block supports only data type double on its inputs and its outputs. I don't see the nessity or possibility to deal with data type datetime or duration. But maybe it is possible to write a function within a MATLAB Function block with double inputs and double outputs where you convert those doubles into datetime and/or duration and convert the results back to doubles. But I am not sure if that is what you want

サインインしてコメントする。

カテゴリ

製品

リリース

R2023a

質問済み:

MP
2023 年 8 月 25 日

コメント済み:

2023 年 8 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by