remove rows in table based on criteria across two columns

14 ビュー (過去 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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by