当一列的数字在另一列的字符串内时删除 table 行

Delete table row when number from one column is within a string in another column

下面显示了一个 table,其中第三列是双精度元胞数组,最后一列是字符元胞数组。我想根据 'Subject moved a bit at the beginning of 2nd minute' 包含数字 2 的条件删除第 248 行,该数字等于该行第三列的值。 我已经通过以下方式实现了它:

commentMinNum = regexp(cellfun(@string, T2.comments(:)),'\d','Match');
commentMinNumInd = find(~cellfun(@isempty, commentMinNum));
extractMinNum = cell2mat(cellfun(@double, commentMinNum, 'UniformOutput', false));
deleteCond = T2.minNum(commentMinNumInd) == extractMinNum;
T2(commentMinNumInd(deleteCond), :) = [];

对于这样一个简单的任务,此实现似乎复杂而冗长。我想知道是否有更直接的方法。我错过了什么或者 Matlab 要我受苦吗? :)

给定 table t:

name = {'TLVPivotal07';'TLVPivotal07';'TLVPivotal07'};
regularityStatus = [1;1;0];
minNum = [1;2;3];
comments = {'Subject moved a bit at the beginning of the 2nd minute';
'Subject moved a bit at the beginning of the 2nd minute';
'Subject moved a bit at the beginning of the 2nd minute'};

t = table(name,regularityStatus,minNum,comments);

使用正则表达式检查第二列中的值是否在注释字符串中的可能解决方案:

indx = (1:numel(t.comments)).';
tInd = ~cellfun(@isempty,arrayfun(@(x,y) regexp(t.comments(y), [num2str(x) '[a-z]{2} minute'],'match','once'),t.minNum,indx));
t(tInd,:) = []

将删除所需的行。