如何选择不在我的索引向量MATLAB中的索引

时间:2017-01-25 13:09:46

标签: matlab indexing

通过A矩阵考虑m n。我想通过随机选择A列来分列NumOfRandomColumn列。 我已经使用此代码生成随机索引的向量并提取第一部分:

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

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

这不起作用:

secondSection=A(:,~indexes);

1 个答案:

答案 0 :(得分:1)

这应该有效:

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

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

相关问题