counter increment based on sample time

8 Ansichten (letzte 30 Tage)
chandru.times
chandru.times am 15 Aug. 2016
Kommentiert: Dhanush am 5 Feb. 2021
1) In matlab simulink, I want to increment a counter variable if the status of a variable is high. The increment should happen by 1 for every sampling period(100 msec). How to achieve this?

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 15 Aug. 2016
Can you explain how to identify if a variable is high or not? what kind of signal gives you this status? If you provide this signal, let us call it signal. Then you can use a switch block, or a Matlab function block
function counter=fcn(signal)
persistent c
if isempty(c)
counter=0 % Initial condition of your counter
end
if signal==1 % if a signal is high
signal=c+1
c=signal
end
  1 Kommentar
Dhanush
Dhanush am 5 Feb. 2021
Also set the sampling rate of the above function block to the rate you want to achieve, i.e., 100ms.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by