如何删除列中有“-”的行?
How to remove rows have ' - ' in their columns?
我有一个大小为 (37080*2) 的元胞数组,我想删除第 1 列或第 2 列中具有“-”的行。
cell={'gif','ghf';'feh','-';'ACACA','BRCA1';'-','TBCD';'NKX3-1','ATXN1'}
想要的输出:
{'gif','ghf';'ACACA','BRCA1';'NKX3-1','ATXN1'}
我试过 strcmp
但我只遇到错误。
for row1 = 1:size(cell,1)
if strcmp(cell(row1,1),'-')|| strcmp(cell(row1,2),'-')
cell(row1,:) = [];
end
end
这个方法应该有效。 strcmp 适用于单元格和 returns 矩阵。然后只需在第二个维度上使用 any
。
c={'gif','ghf';'feh','-';'ACACA','BRCA1';'-','TBCD';'NKX3-1','ATXN1'}
c(any(strcmp(c,'-'),2),:)=[]
输出:
3×2 元胞数组
'gif' 'ghf'
'ACACA' 'BRCA1'
'NKX3-1' 'ATXN1'
我有一个大小为 (37080*2) 的元胞数组,我想删除第 1 列或第 2 列中具有“-”的行。 cell={'gif','ghf';'feh','-';'ACACA','BRCA1';'-','TBCD';'NKX3-1','ATXN1'} 想要的输出: {'gif','ghf';'ACACA','BRCA1';'NKX3-1','ATXN1'}
我试过 strcmp
但我只遇到错误。
for row1 = 1:size(cell,1)
if strcmp(cell(row1,1),'-')|| strcmp(cell(row1,2),'-')
cell(row1,:) = [];
end
end
这个方法应该有效。 strcmp 适用于单元格和 returns 矩阵。然后只需在第二个维度上使用 any
。
c={'gif','ghf';'feh','-';'ACACA','BRCA1';'-','TBCD';'NKX3-1','ATXN1'}
c(any(strcmp(c,'-'),2),:)=[]
输出:
3×2 元胞数组
'gif' 'ghf'
'ACACA' 'BRCA1'
'NKX3-1' 'ATXN1'