如何从单元格数组中删除一组特定的行?

时间:2012-11-29 12:08:58

标签: matlab octave

我有一个约6000行的单元格数组。接下来,我有一个带有一组行索引的向量,我们称之为removalIdx。我想创建一个新的单元格数组,其中包含removalIdx指定的行的原始单元格数组EXCEPT中的所有行。关于如何在不恢复for循环的情况下执行此操作的任何想法?

1 个答案:

答案 0 :(得分:3)

以下示例代码应该回答您的问题:

B = {'hello';'world';'are';'you';'there'}; %# Example cell array
ToRemove = [2; 4]; %# Example indices to remove
Soln = B; %# Create the new cell array
Soln(ToRemove) = []; %# Remove the offending rows

请注意:

>> Soln

Soln = 

    'hello'
    'are'
    'there'