- Only need to specify one place, leave the other as -1
- You could specify both but they need to be the same. Otherwise, there would be an error.
Differences between the two Sample time settings in the MATLAB Function block in Simulink
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
雪飞
el 6 de Oct. de 2023
Comentada: Fangjun Jiang
el 10 de Oct. de 2023
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:
- Screenshot 1: https://www.mathworks.com/help/releases/R2022b/simulink/slref/matlabfunction.html
- Screenshot 2: https://www.mathworks.com/help/releases/R2022b/simulink/ug/matlab-function-block-properties.html
I truly appreciate your assistance and expertise in this matter.
Screenshot 1:
![Screenshot 1](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1503934/Screenshot%201.png)
Screenshot 2:
![Screenshot 2](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1503939/Screenshot%202.png)
0 comentarios
Respuesta aceptada
Fangjun Jiang
el 6 de Oct. de 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
4 comentarios
Paul
el 7 de Oct. de 2023
Editada: Paul
el 7 de Oct. de 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 =
'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.
Fangjun Jiang
el 10 de Oct. de 2023
@Paul, you are right. It is a "special" Subsystem block and not masked.
Más respuestas (0)
Ver también
Categorías
Más información sobre Event Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!