How can the previous value of a block input be accessed in a tlc file?

3 次查看(过去 30 天)
[EDIT: 20110610 20:22 CDT - reformat - WDR]
I am writing a tlc file and inside %function Update(block, system) Output, I would like to use both the current value and previous value of the block input as
d = %<LibBlockInputSignal(0, "", "", 0)> - (the value of %<LibBlockInputSignal(0, "", "", 0)> at the previous sampling instant);
I can access the current value using %<LibBlockInputSignal(0, "", "", 0)> but I do not know how to access the previous value. I cannot use
d = %<LibBlockInputSignal(0, "", "", 0)> - d;
since d is a local variable initialized to zero (or something else) inside the function and the above statement is equivalent to
d = %<LibBlockInputSignal(0, "", "", 0)>;
Is there a function I can use for this purpose? How can I make d a global variable so that it retains its previous value?

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2011-6-12
There is no direct way to access the previous input of an S-function in TLC, just as there is no way to access it in the corresponding MATLAB or C/C++ source code definition of the S-function. You need to create a work vector, and store the value of the input in the current time-step for use in the next time-step.
To see a C-MEX S-function (with TLC) example of storing the previous input in a work vector, type the model name at the MATLAB prompt:
>> sfcndemo_sfunmem

类别

Help CenterFile Exchange 中查找有关 Target Language Compiler 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by