Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Store and pass on variables
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to store a value to be passed on in Simulink, whenever certain conditions is met. Preferrably using a Matlab function block.
The code i've written is the following:
function prev_tan = fcn(input)
persistent tangent;
persistent prev_tangent;
% Initial values
if isempty(prev_tangent)
prev_tangent = [1; 1];
tangent = [1; 1];
% When u changes
elseif tangent ~= input
prev_tangent = tangent;
tangent = input;
end
prev_tan = prev_tangent;
end
Anyone know how to do this or something similar, storing old values to be passed on?
Thanks in advance!
0 Kommentare
Antworten (1)
Patel Mounika
am 12 Mär. 2019
System Objects are designed specifically for implementing and simulating dynamic systems with inputs that change over time and System objects use internal states to store that past behavior, which is used in the next computational step which is applicable in your case. Therefore, I suggest you use System Objects rather than functions. And MATLAB System Block will enable you to use System Objects in Simulink. Please refer to the links to know more about System Objects and System block.
https://www.mathworks.com/help/matlab/matlab_prog/what-are-system-objects.htmlhttps://www.mathworks.com/help/simulink/ug/what-is-matlab-system-block.html
Hope this helps.
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!