# Identify the duration of zero values and count the number of such zero regions

3 Ansichten (letzte 30 Tage)
Reji G am 1 Dez. 2022
Kommentiert: Image Analyst am 1 Dez. 2022 Hello,
I have a signal shown above.
1. First I want to identify the duration(length) of each zero valued regions represented as T, T1, T2, T3 etc., (You may generate any signal with zeroed region similar to my graph)
2. Count how many such zero valued regions are there in 1 sec(or within a specified time).
Any help interms of code is well appreciated. Thank you in advance.
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Davide Masiello am 1 Dez. 2022
Bearbeitet: Davide Masiello am 1 Dez. 2022
time = 0:100;
signal = rand(size(time));
signal([3:6,15:21,43:55,61:64,87:92]) = 0;
plot(time,signal) r = regionprops(signal==0,"SubarrayIdx");
for k = 1:length(r)
time_indexes = r(k).SubarrayIdx{2};
durations(k) = time(time_indexes(end))-time(time_indexes(1));
end
durations
durations = 1×5
3 6 12 3 5
Obviously, the number of zero regions is the length of the array durations.
##### 3 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Image Analyst am 1 Dez. 2022
Or, more simply
zeroRegions = (signal == 0); % Identify elements that are exactly 0.
% Throw out runs less than, say, 3 elements long.
zeroRegions = bwareaopen(zeroRegions, 3);
% Measure what's left (regions 3 or more elements long).
r = regionprops(zeroRegions,"Area");
durations = [r.Area] % Extract all run lengths from structure into vector.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Descriptive Statistics in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!