Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

consecutive rows to define an event

2 visualizaciones (últimos 30 días)
Vanessa
Vanessa el 15 de Mayo de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hello everyone, I have a dataset array in which the first column contains the number of each row of the array and the second column is a parameter (0 or 1). I want to find consecutive rows(4 and more) with 1 in the second column and create seperate matrixes with these arrays. I would appreciate any help.
Thanks, Vanessa

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 15 de Mayo de 2017
Editada: Andrei Bobrov el 15 de Mayo de 2017
Let A - your dataset with size [N x 2]
Using Image Processing Toolbox
1.
S = regionprops(cumsum(diff([0;A(:,2)]) == 1).*A(:,2) ,'Area','PixelIdxList');
out = cellfun(@(x)A(x,:),{S([S.Area] >= 4).PixelIdxList},'un',0)
2.
i0 = bwareaopen(A(:,2),4);
i1 = bwlabel(i0);
i2 = (1:size(A,1))';
out = accumarray(i1(i0),i2(i0),[],@(x){A(x,:)})
other way without Image Processing Toolbox
1.
ii = cumsum(diff([0;A(:,2)]) == 1).*A(:,2);
t = A(:,2)~=0;
i1 = accumarray(ii(t),1);
i2 = i1>=4;
A1 = A(t,:);
out = mat2cell(A1(ismember(ii(t),find(i2)),:),i1(i2),size(A,2));
2.
ii = cumsum(diff([0;A(:,2)]) == 1).*A(:,2);
C = accumarray(ii+1,(1:size(A,1))',[],@(x){A(x,:)});
C = C(2:end);
out = C(cellfun('size',C,1) >= 4);
  1 comentario
Vanessa
Vanessa el 16 de Mayo de 2017
It worked!!Thank you very much for your help!!!

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by