How to feed the output of a user defined embedded function back into one of the inputs?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I would like to feed back one of the outputs of my user defined embedded function (Matlab Function block) back into one of the inputs (of the same function block) during the next iterative cycle.
May I know how can this be done? Thanks alot for helping!
0 Kommentare
Antworten (2)
Kaustubha Govind
am 6 Mär. 2012
Connecting an output back as an input will cause algebraic loops, so you may see errors or warnings from the Simulink solver when you do this. The best thing might be to maintain an internal state to save the previous output and use in the next time-step. For example:
function y = mytest(u)
%#codegen
persistent prev_y; %internal state
if isempty(prev_y)
prev_y = 0; %initial value
end
y = 2*u + prev_y;
prev_y = y;
0 Kommentare
Bassam Saleh
am 4 Sep. 2015
using a memory block beyond the o/p signal and in-front of the i/p signal will solve this issue.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Schedule Model Components finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!