Get sample rate in a Matlab function block in Simulink
조회 수: 29(최근 30일)
표시 이전 댓글
If i use MATLAB function block in a Simulink project, is there a way of determining the sample rate in the code in that block? If I use a MATLAB System block, I can use getSampleTime(obj).SampleTime to give me the time for a frame and then use the frame size to give me the time for a sample, but that won't work for a MATLAB function block. I'd like to use the MATLAB function block if possible because the coding is simple. Is there a way to get the sample rate or am I stuck using a MATLAB system block?
답변(2개)
jibrahim
2021년 12월 28일
Hi Glenn,
I've accomplished this in the past using a probe block:
That block can output a vector representing the sample time. You should be able to feed this value to your MATLAB function block (as an input) and use the value.
댓글 수: 2
jibrahim
2021년 12월 28일
You might be able to accomplish this by calling simulink.block.getSampleTimes inside the MATLAB function block:
However, that function does not generate code, so you will have to use it in conjunction with coder.extrinsic and coder.const. I think using a probe block is much more straightforward.
Salman Ahmed
2021년 12월 31일
Hi Glenn,
You could also use the following workaround to access the sample rate inside the MATLAB function block:
coder.extrinsic('get_param');
sampleTime=str2double(get_param('s1/MAT','SystemSampleTime'));
Here s1 is the Simulink model name, MAT is the name of the MATLAB function block.
댓글 수: 0
참고 항목
범주
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!