How do I write a function that alternates an output variable between 0 and 1 every 1 second?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Youssef Elrakhawy
am 27 Okt. 2022
Beantwortet: Eric Delgado
am 27 Okt. 2022
I'm trying to find a solution for my stateflow project in which I want to alternate an output signal as stated in the summary.
0 Kommentare
Akzeptierte Antwort
Eric Delgado
am 27 Okt. 2022
Create a timer with its "UserData" property set to 0. And a timer function (you have to save it to a file) to switch this value between 0 and 1. Hope it helps! :)
% Timer
tmr = timer('Period', 1, ...
'ExecutionMode', 'fixedRate', ...
'TimerFcn', @tmrFunction, ...
'UserData', 0);
start(tmr)
% Timer function
function tmrFunction(Source, Event)
switch Source.UserData
case 0; Source.UserData = 1;
case 1; Source.UserData = 0;
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Stateflow 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!