Obtain sample time in Embedded Matlab block

Sorry if this has been asked many times before, but I couldn't find an answer.
If I have an embedded Matlab block with inherited sample time, can I somehow obtain the evaluated sample time in the code of the embedded block at runtime? This is possible for an S-function and it would be really sweet if it was possible for embedded blocks as well.

답변 (3개)

Ryan G
Ryan G 2012년 7월 30일

1 개 추천

I don't believe you can do this directly but you could use this code in the EML block with a clock as an input:
function y = fcn(u)
%#codegen
persistent time12
if isempty(time12)
time12 = 0;
end
deltaT = u - time12;
time12 = u;
y = deltaT;
Where the block is at the same inherited sample rate.
Azzi Abdelmalek
Azzi Abdelmalek 2012년 7월 30일
편집: Azzi Abdelmalek 2012년 7월 30일

0 개 추천

you can use a "zoh" block (simulink/discret/Zero Order Holder), with a sample time of your choice. You place it at the inputs (or/and) outputs of the embedded matlab function block
Anders
Anders 2012년 7월 31일

0 개 추천

So basically it's not easily obtainable then. Thanks for those answers anyway. I guess I will have to make a feature request if someone hasn't already. There should be a possibility to access a struct with simulation info or something similar. Not supported on all target hardware of course but for simulation at least.

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

제품

질문:

2012년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by