Is there a MATLAB simulation time command supported by Simulink Design Verifier?

2 ビュー (過去 30 日間)
Joshua
Joshua 2024 年 10 月 17 日
回答済み: TED MOSBY 2024 年 10 月 19 日
I am working on a Simulink model with a MATLAB Function block. The function in the function block requires the current simulation time. At the moment this is solved via an input with a Digital Clock block.
Is there a MATLAB command that could do this and is compatible with the Simulink Design Verifier?
  4 件のコメント
Pat Canny
Pat Canny 2024 年 10 月 18 日
I got several options from some internal experts:
  • To get the simulation time at the MATLAB prompt: "get_param(bdroot,'SimulationTime')"
  • To get the simulation time inside a MATLAB System block: matlab.system.getcurrenttime
  • To get the simulation time inside a Stateflow chart (MATLAB action language): getSimulationTime();
  • To get the simulation time inside a MATLAB Function block: we don't think there is a function for that. If the block is fixed-step discrete, the recommendation is to take the sample time as a parameter and count the time in the code.
Hopefully that helps. If so, let me know and I can submit this as an Answer.
Joshua
Joshua 2024 年 10 月 18 日
Hi
Yes that was very helpfull.
Thank you.

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

採用された回答

TED MOSBY
TED MOSBY 2024 年 10 月 19 日
Hi @Joshua,
In a MATLAB Function block in Simulink, you can access the current simulation time without needing a Digital Clock block. You can do this by passing the simulation time as an input to your function.
Add a Clock Block:
  • In your Simulink model, add a Clock block from the Simulink library (found under Sources).
Connect the Clock Block:
  • Connect the output of the Clock block to the input of your MATLAB Function block. This will pass the current simulation time to the function.
Define the MATLAB Function:
  • Edit your MATLAB Function block to accept the simulation time as an input. Here’s an example of how to define your function:
function output = myFunction(time)
% Use the current simulation time
currentTime = time;
% Example operation using current time
output = currentTime^2; % Replace with your desired computation
end
Hope this helps!
Here is the documentation for the “clock block”:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by