How to detect given pattern and delete the current row
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I have below cell array (i am using matlab 2016a),
I want to delete rows if match the below criterion:
For every current row contains: Column1 is : Passed, Column2 is Auto, and column3 is 1 & and if Previous row: column1 is Manual & column2 is Passed. Then Remove current row.
Input:
Strucked Atomatic 23
Passed Mannual 41
Passed Automatic 1
Strucked Atomatic 23
Passed Mannual 41
Passed Mannual 126
Passed Automatic 1
Desired output:
Strucked Atomatic 23
Passed Mannual 41
Strucked Atomatic 23
Passed Mannual 41
Passed Mannual 126
채택된 답변
Jan
2018년 10월 16일
편집: Jan
2018년 10월 16일
C = {'Strucked', 'Atomatic', 23; ...
'Passed', 'Mannual', 41; ...
'Passed', 'Automatic', 1; ...
'Strucked', 'Atomatic', 23; ...
'Passed', 'Mannual', 41; ...
'Passed', 'Mannual', 126; ...
'Passed', 'Automatic', 1};
if current row: Column1 is : Passed, Column2 is Auto,
and column3 is 1 & in Previous row:
column1 is "Manual & column2 is Passed. Then Remove current row.
match1 = strcmp(C(:, 1), 'Passed') & ...
strcmp(C(:, 2), 'Automatic') & ...
cat(1, C{:, 3}) == 1;
match2 = strcmp(C(:, 1), 'Manual') & ...
strcmp(C(:, 2), 'Passed');
match = match1 & [false; match2(1:end-1)]; % FALSE: no "previous" for 1st element
Result = C(match, :)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!