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

5 views (last 30 days)
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

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 6 Oct 2023
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.
Paul on 7 Oct 2023
Edited: Paul on 7 Oct 2023
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 =
>> get_param(gcb,'BlockType')
ans =
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.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!