remove rows in table based on criteria across two columns

19 次查看(过去 30 天)
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-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 个评论

请先登录,再进行评论。

类别

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