How to find all first records of specified item between each specified case in the table

1 visualización (últimos 30 días)
Hi,
I have the below table, and I want to extract all first records (appear first time after calibration) of "End" after each calibration.
Case1: If the first record after calibration is "End" just extract that row.
Cae2: If the first record after calibration is not "End", and check for the "End" record before next calibration, and take that row (if "End" exist before next calibration)
Case3: If no "End" record exists before next calibration, just take the last record before next calibration.
Kindly help, Many thanks in advance,
Calibration HT0MEK
End HT0MEK
Calibration JT0KEL
Paused T0KEL
End JT0KEL
End JT0KEL
Calibration BK0JIL
Paused HA0GEK
Paused HA0GEK
My output should be: (Row 2, Row 5, and Row 9)
Output:
End HT0MEK
End JT0KEL
Paused HA0GEK
Many thanks in advance

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 16 de Abr. de 2016
Editada: Azzi Abdelmalek el 16 de Abr. de 2016
Edit
v={'Calibration' 'HT0MEK'
'End' 'HT0MEK'
'Calibration' 'JT0KEL'
'Paused' 'T0KEL'
'End' 'JT0KEL'
'End' 'JT0KEL'
'Calibration' 'BK0JIL'
'Paused' 'HA0GEK'
'Paused' 'HA0GEK'
'Calibration' 'HA0GE'}
c1=v(:,1);
idx1=find(ismember(c1,'Calibration' ))
idx1=[ones(size(idx1)) idx1]
idx2=find(ismember(c1,'End' ))
idx2=[2*ones(size(idx2)) idx2]
h=sortrows([idx1;idx2],2)
ii=strfind(h(:,1)',[1 2])+1
ind1=h(ii,2)
jj=strfind(h(:,1)',[1 1])+1
ind2=h(jj,2)-1
ind=sort([ind1;ind2])
out=v(ind,:)

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by