How to stop simulation until the workspace data end?

There is a input from workspace. (this block be can found in Sources categories. ) Whenever I simulate a block, I should change the simulation time at the top of the diagram. (just side by stop button.)
My question is, How can I stop simulation when the input are finished? (the input has 2 columns - time, value)
ex:)
the input like below:
time, value
0, 35
1, 20
2, -10
... ...
10, 5
I would like to stop my diagram at 10sec.

 采纳的回答

There are two ways....
(1) Set the stop time of your model using time value as
set_param('YourModel', 'StopTime', num2str(WSData.time(end)));
then simulate your model.
(2) Simulate your model directly using sim() command by providing stop time as parameter.
sim('YourModel', WSData.time(end));

3 个评论

Thank you for your answer, but the WSData is not a structure, but array.
so I changed 'WSData.time(end)' to ' WSData(end,1)'
and it works well. :-)
Ok, I assumed that your workspace data is in the format of "Structure with time".
Wow, not only your answer but also your comment are real time~! :-)
Your advice is very helpful for my model. thank you again~

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by