I have a signal of a switch with ON/OFF situation. How can I get how many times it actuates by matlab, simulink, or script?
5 次查看(过去 30 天)
显示 更早的评论
When the value is not equal to previous value, the counter should be increased by 1. I want total count in a certain time period.
0 个评论
采纳的回答
更多回答(1 个)
Image Analyst
2016-1-5
Maybe something like this:
loopCounter = 0;
count = 0;
oldSwitchReading = -1;
stillCheckingSwitch = true;
while stillCheckingSwitch && loopCounter < 1000000
thisSwitchReading = % Some code to read your switch.....
if thisSwitchReading ~= oldSwitchReading
count = count + 1;
end
oldSwitchReading = thisSwitchReading; % New/current state is now the old state for the next iteration.
loopCounter = loopCounter + 1; % Increment fail-safe.
% Decide if we need to quit checking the switch
stillCheckingSwitch = % Code to determine when to quit.....
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!