counter that will count the input 1. If the input signal goes to 0 then the counter should reset.
1 次查看(过去 30 天)
显示 更早的评论
I have to count every "True" signal and increment the counter by 1, when the signal is "True" and reset the counter to 0 when the signal is "False"
0 个评论
回答(1 个)
Matlab Pro
2024-6-4
Hi
I have created a dummy "signal" variable that gets the value True or False.
Hope this fits your needs
counter = 0;
for i = 1:1000
signal = rand > 0.5;
if signal == 1
counter = counter+1;
else
counter = 0;
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!