How can the previous value of a block input be accessed in a tlc file?
이전 댓글 표시
[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
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
카테고리
도움말 센터 및 File Exchange에서 Target Language Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!