# Identifying time for prolong changes in a sequence

1 visualización (últimos 30 días)
Tino el 6 de Jul. de 2021
Comentada: Image Analyst el 12 de Jul. de 2021
Hello
Please I have a sequence for instance
010001100000111110000100011001
And I want to identify the ones that are more than 2(onces) and the time
for this example is 5 seconds
Also another example is when I have more than one occurances of 1 greater than 2
000001110001111001000110001
Then the time are [ 3sec 4sec]
I have used the code A = seconds(x)
It only shows me a total number of 1 in seconds.
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

Image Analyst el 6 de Jul. de 2021
Try this (requires the Image Processing Toolbox):
binarySequence = [0 1 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1];
props = regionprops(logical(binarySequence), 'Area');
allLengths = [props.Area]
% Count number of regions longer than some number:
maxLength = max(allLengths)
for k = 1 : maxLength
longerThanN = sum(allLengths == k);
fprintf('There are %d sequences of %d.\n', longerThanN, k);
end
You get:
There are 3 sequences of 1.
There are 2 sequences of 2.
There are 0 sequences of 3.
There are 0 sequences of 4.
There are 1 sequences of 5.
##### 10 comentariosMostrar 9 comentarios más antiguosOcultar 9 comentarios más antiguos
Image Analyst el 12 de Jul. de 2021
Try this:
binarySequence = [0 1 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1]
% Measure the data
props = regionprops(logical(binarySequence), 'Area', 'PixelIdxList');
allLengths = [props.Area]
% Count number of regions longer than some number:
maxLength = max(allLengths)
for k = 1 : maxLength
% Get the labels for this length
labels = allLengths == k;
longerThanN = sum(labels);
fprintf('There are %d sequences of %d.\n', longerThanN, k);
indexes{k} = find(labels);
for k2 = 1 : length(indexes{k})
fprintf(' Sequence %d\n', indexes{k}(k2));
end
% Get 1's wherever the run has a length of k.
locations = zeros(size(binarySequence));
for k2 = 1 : length(labels)
if labels(k2)
locations(props(k2).PixelIdxList) = 1;
end
end
% Report to the command window:
%locations
end
There are 3 sequences of 1.
Sequence 1
Sequence 4
Sequence 6
There are 2 sequences of 2.
Sequence 2
Sequence 5
There are 0 sequences of 3.
There are 0 sequences of 4.
There are 1 sequences of 5.
Sequence 3

Iniciar sesión para comentar.

### Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

R2020a

### Community Treasure Hunt

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

Start Hunting!