通过施加条件来删除特定行

时间:2019-06-05 07:54:07

标签: matlab structure strncmp

我有一个由“名称”列和“数据”列组成的结构。

enter image description here 我需要通过对特定名称强加条件来删除一系列行。 我在另一练习中使用了此代码,这似乎还不错,但我想这是不正确的:

    sn = {'Adattamento ad una distrib._HID',...
          'Adattamento ad una distrib._HI1',...
          'TUTTI','Modelling','Sheet37','Sheet52'}; % fogli da escludere

   SheetNames = {S.Name}; %% 

    for jj = 1:length(sn)
      SheetNames = {S.Name};
      S = S(~strncmp(SheetNames, sn(jj),jj));
      %jj = numel(sn)-1; % aggiorna l'indice
    end  

---------------------------- 更新 ----------- ------------------------- 我理解了这个问题。

我的S.Name结构是这样制成的:

SheetNames = {S.Name};



  This is {S.Name} :

    {'Ar1';'Adattamento ad una distrib._HID';'Adattamento ad una distrib._HI1';...;'Ar2';'Ar35';...;
'Cos1';'Cos2';'Cos31';...;'Tex1';'Tex2';....;
'Sheet37_HID';'Tex8';.....;'Tex30';'Tu1';'Tu2';'Tu3';...;'Tu32';
'TUTTI';'Modelling';'Sheet52'}

如果

 sn = {'Adattamento ad una distrib._HID',...
          'Adattamento ad una distrib._HI1',...
          'TUTTI','Modelling','Sheet37','Sheet52'};

最终结构S将不再包含以 A T M S

S = 1x128,循环后变成S = 1x91

2 个答案:

答案 0 :(得分:1)

我想到的最简单的解决方案是使用const foo = () => this.setState(prevState => ({ ...prevState, parentDisableRipple: true })); const enableRipple = () => this.state.parentDisableRipple && this.setState(prevState => ({ ...prevState, parentDisableRipple: false })); return ( <div> <Hello name={this.state.name} /> <p> Start editing to see some magic happen :) </p> <ListItem button={true} disableRipple={this.state.parentDisableRipple} onClick={enableRipple()}> <Typography variant='caption' color='primary'> {value} </Typography> <Button onClick={foo} >Button</Button> </ListItem> </div> ); string

ismember

答案 1 :(得分:0)

让数据定义为

S(1).Name = 'Ar1'; S(1).Data = [1 2 3];
S(2).Name = 'Adattamento ad una distrib._HID'; S(2).Data = 'abcd';
S(3).Name = 'Adattamento ad una distrib._HI1'; S(3).Data = [true; false];
S(4).Name = 'Ar4'; S(4).Data = {'4' '5'};
sn = {'Adattamento ad una distrib._HID',...
      'Adattamento ad una distrib._HI1',...
      'TUTTI','Modelling','Sheet37','Sheet52'};

然后,您可以使用ismember和逻辑索引,如下所示:

result = S(~ismember({S.Name}, sn));