Differences between the two Sample time settings in the MATLAB Function block in Simulink

3 次查看(过去 30 天)
I have a question regarding the MATLAB Function block in Simulink, specifically about the two Sample time settings shown in the attached screenshots (screenshots 1 and screenshots 2).
I would be extremely grateful if you could kindly explain the differences between these two settings and how they impact the behavior of the block. Furthermore, I am interested in understanding any recommended best practices or scenarios where one setting should be favored over the other. Could someone provide clarification on this matter?
For detailed reference, you can navigate to the screenshot interface by clicking on this link:
I truly appreciate your assistance and expertise in this matter.
Screenshot 1:
Screenshot 1
Screenshot 2:
Screenshot 2

采纳的回答

Fangjun Jiang
Fangjun Jiang 2023-10-6
This is a really good question. I've never noticed it before. I'll provide my take on it. You could contact the Mathworks' tech support for an official answer.
First of all, a MATLAB Function block is actually a masked subsystem. Run get(gcbh,'Blocks') on a default MATLAB Function block returns the blocks below, which reflect the default input, output and other stuff.
>> get(gcbh,'Blocks')
ans =
5×1 cell array
{'u' }
{' Demux ' }
{' SFunction ' }
{' Terminator '}
{'y' }
So, Screenshot 1 approach, let's call it Block Dialog, can be brought up by right clicking the MATLAB Function block, selecting "Block Parameters (Subsystem)". It specifies the sample time of the masked subsystem. This sample time is available to be set only when "Treat as atomic unit" option is checked.
Screenshot 2 approach, there are actually two ways, Property Inspector or Model Explorer. They have the same effect. Changing the sample time in one way would automatically be reflected in the other way. This approach specifies the sample time of the ' SFunction ' block which let's assume is the "core" of the MATLAB Function block. Please also note that this sample time could also be grayed out when the "update method" is continuous.
So, overall, treat these two sample times as one is for the subsystem and the other is for a block inside the subsystem.
When everything is in default, or when both samle times are activated or apply
  1. Only need to specify one place, leave the other as -1
  2. You could specify both but they need to be the same. Otherwise, there would be an error.
  4 个评论
Paul
Paul 2023-10-7
编辑:Paul 2023-10-7
I don't think the Matlab Function block is a masked system. It looks like it's an ordinary subsystem
>> get_param(gcb,'Mask')
ans =
'off'
>> get_param(gcb,'BlockType')
ans =
'SubSystem'
It could be atomic or not depending on the check box in the block parameters.
If the Sample Time of the Matab Function block is -1 (inherited) then it will execute at the Sample Time of the Clock, which is 'continuous'. Signals with continuous sample time are evaluated at steps determined by the solver, which in turrn can be influenced by sample times of other blocks in the model if you're using a variable step solver.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by