【问题标题】:How to pick indices that are not in my indices vector MATLAB如何选择不在我的索引向量 MATLAB 中的索引
【发布时间】:2017-01-25 13:09:45
【问题描述】:

考虑Am by n 矩阵。我想通过随机选择NumOfRandomColumn 列来明智地拆分A 列。 我已使用此代码生成随机索引向量并提取第一个部分:

indexes=randsample(1:MatrixColumnNumber, NumOfRandomColumn);
firstSection=A(:,indexes);

如何提取第二部分,即不在'indexes'中的索引?

这不起作用:

secondSection=A(:,~indexes);

【问题讨论】:

    标签: matlab indexing


    【解决方案1】:

    这应该可行:

    notselected = 1:MatrixColumnNumber;
    notselected(indexes) = [];
    secondSection = A(:,notselected);
    

    这基本上是一种形成 1:N 和您选择的索引集之间差异集的方法。这也可以使用setdiff 完成,但我记得setdiff 比上面的要慢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 1970-01-01
      相关资源
      最近更新 更多