remove rows in table based on criteria across two columns

19 vues (au cours des 30 derniers jours)
DavidL88
DavidL88 le 3 Nov 2021
Commenté : DavidL88 le 5 Nov 2021
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

Réponse acceptée

Turlough Hughes
Turlough Hughes le 3 Nov 2021
Modifié(e) : Turlough Hughes le 3 Nov 2021
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 commentaires
DavidL88
DavidL88 le 3 Nov 2021
That worked thanks.
DavidL88
DavidL88 le 5 Nov 2021
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') = [];

Connectez-vous pour commenter.

Plus de réponses (1)

DavidL88
DavidL88 le 3 Nov 2021
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 commentaires
DavidL88
DavidL88 le 3 Nov 2021
Thanks. I attach sample here.
Turlough Hughes
Turlough Hughes le 3 Nov 2021
I've edited my answer above.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by