Matlab中的补集子集 [英] Complement subset in Matlab
问题描述
在R中,我可以执行以下操作:
In R, I can do the following:
v <- 11:20
v[-(4:5)]
并获得11 12 13 16 17 18 19 20
,因此所有索引 均排在第4位和第5位.
and get 11 12 13 16 17 18 19 20
, thus all indices except the 4th and 5th.
Matlab的索引逻辑是否等效?
Is there an equivalent in Matlab's indexing logic?
但是我全神贯注于此,对于这个相当基本的问题,我似乎没有找到正确的搜索词来搜索我自己的结果.
However I wrap my mind around it, I do not seem to get the correct search terms to google my own result for this fairly elementary question.
注意:当然,我可能会使用某些设置函数,例如
Note: Of course I might use some of the set functions, e.g.
v = 11:20;
v(setdiff(1:length(v), 4:5))
但是,这只是不直观的.
However, this just is not intuitive.
推荐答案
另一种方法是简单地从数组中删除元素:
An alternative is to simply remove the elements from the array:
u = v;
u(4:5) = [];
我正在使用一个临时变量,因为我不知道修改原始数组v
是否可接受.
I'm using a temporary variable since I don't know if it's acceptable to modify the original array v
or not.
这篇关于Matlab中的补集子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!