remove rows in table based on criteria across two columns

조회 수: 17 (최근 30일)
DavidL88
DavidL88 2021년 11월 3일
댓글: DavidL88 2021년 11월 5일
How do I remove rows based on whether or not a substring in one column matches with a number in a second column according to a pre-defined criteria?
The criteria;
80ms,140ms & 1
100ms,250ms & 2
250ms,600ms & 3
600ms,900ms & 4
An example of the data below. I want to delete the rows below where 250ms,600ms is in the first column and the number in the second column is a number other than 3, and delete rows where 100ms,250ms is in the first column and a number other than 2 is in the second column.
'CG_11_21_250ms,600ms_CPR' 1
'CG_11_21_250ms,600ms_CPR' 2
'CG_11_21_250ms,600ms_CPR' 3
'CG_11_21_250ms,600ms_CPR' 4
'CG_12_22_100ms,250ms_FCL' 1
'CG_12_22_100ms,250ms_FCL' 2
'CG_12_22_100ms,250ms_FCL' 3
'CG_12_22_100ms,250ms_FCL' 4

채택된 답변

Turlough Hughes
Turlough Hughes 2021년 11월 3일
편집: Turlough Hughes 2021년 11월 3일
Try the following:
T(contains(string(T{:,1}),'80ms,140ms') & T{:,2} ~= 1,:) = [];
T(contains(string(T{:,1}),'100ms,250ms') & T{:,2} ~= 2,:) = [];
T(contains(string(T{:,1}),'250ms,600ms') & T{:,2} ~= 3,:) = [];
T(contains(string(T{:,1}),'600ms,900ms') & T{:,2} ~= 4,:) = [];
  댓글 수: 3
DavidL88
DavidL88 2021년 11월 3일
That worked thanks.
DavidL88
DavidL88 2021년 11월 5일
Hi Turlough,
Could you advise how I can adapt your code to this table to delete according to two strings? In the adaptation below I outline the two conditions to remove the row but I get this 'Operator '&' is not supported for operands of type 'string'.'
T(contains(string(T{:,2}),'11_right') & string(T{:,3}),'earlyP3') = [];
T(contains(string(T{:,2}),'21_right') & string(T{:,3}),'earlyP3') = [];

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

DavidL88
DavidL88 2021년 11월 3일
Thanks for your reply. I'm getting this error?
Error using contains
First argument must be a string array, character vector, or cell array of character vectors.
  댓글 수: 3
DavidL88
DavidL88 2021년 11월 3일
Thanks. I attach sample here.
Turlough Hughes
Turlough Hughes 2021년 11월 3일
I've edited my answer above.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by