필터 지우기
필터 지우기

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.
Fangjun Jiang
Fangjun Jiang 2023년 10월 10일
@Paul, you are right. It is a "special" Subsystem block and not masked.

댓글을 달려면 로그인하십시오.

추가 답변 (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