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?
6 views (last 30 days)
Show older comments
shreyas chopade
on 5 Jan 2016
Answered: Image Analyst
on 5 Jan 2016
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 Comments
Accepted Answer
More Answers (1)
Image Analyst
on 5 Jan 2016
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!