2

我有 2 个单元阵列和一个矩阵。第一个名为“all_ids”的单元格数组是一个 6650 x 1 的单元格,其中包含字符串。第二个称为“needed_ids”的单元格数组是“all_ids”的子集,是 6600 x 1 单元格,其中还包含字符串。

名为“sales_num”的矩阵是一个 6650 x 500 的双精度矩阵,此处的行与“all_ids”行相关。我想要做的是从“sales_num”中删除一些行。我要删除的行是“all_ids”中但不在“needed_ids”中的行。请看下面的例子。

                                                    Result I'm looking for
all_ids      sales_num           needed_ids         sales_num (now altered)
abc1         1                   abc1               1
def1         2                   def1               2
ghi1         7                   jkl1               8
jkl1         8                   mno1               4
mno1         4                   stu1               2
pqr1         12
stu1         2
vwx1         5
4

1 回答 1

4

使用setdiff-

[~,row_ind] = setdiff(all_ids,needed_ids) %// Find rows exclusive to all_ids
sales_num(row_ind,:)=[]; %// Remove rows that match the exclusiveness
于 2014-07-16T11:03:30.763 回答