about accessing the time inside embedded

2 ビュー (過去 30 日間)
Hati
Hati 2012 年 7 月 30 日
I am using clock block to access the current simulation time. This block is connected to matlab embedded function inside the Simulink. This time is available inside embedded function for use. I am giving first 15 samples.
0 1.17773E-09 7.06641E-09 3.65098E-08 1.83727E-07 9.1981E-07 4.60023E-06 2.30023E-05 0.000115013 0.000575065 0.002875328 0.014376639 0.034210553 0.060090116 0.091367769
But my problem is I want use "index" of the simulation time also. How can I do so ? Waiting for your reply...Thank you

採用された回答

Sumit Tandon
Sumit Tandon 2012 年 7 月 30 日
編集済み: Sumit Tandon 2012 年 7 月 30 日
What do you mean by the "index" - the step count? In that case you could have a counter running inside the MATLAB Function block. Define the counter as a PERSISTENT variable so that it holds its value from previous step.
For example something like this:
function val = myFunction(x)
persistent counter
if isempty(counter)
counter = 0;
else
counter = counter + 1;
end
val = counter*x;

その他の回答 (1 件)

Shashank
Shashank 2012 年 7 月 30 日
This can be done by the use of persistent variables in the MATLAB Function. Essentially, Simulink 'remembers' the value of the variable, and hence, by incrementing this variable every time the function is entered, the simulation time index can be obtained.
Care must be taken to initialize the persistent variable the first time the MATLAB Function is entered, however.
More information about persistent variables is available at the following link: http://www.mathworks.com/help/toolbox/eml/ug/bq8nvgq.html

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by