Get sample rate in a Matlab function block in Simulink
18 views (last 30 days)
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?
jibrahim on 28 Dec 2021
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.
Salman Ahmed on 31 Dec 2021
You could also use the following workaround to access the sample rate inside the MATLAB function block:
Here s1 is the Simulink model name, MAT is the name of the MATLAB function block.