【发布时间】:2015-09-15 17:06:36
【问题描述】:
我有一个 ID 号重复偶数次的向量。我只对每个数字出现的第二次感兴趣。我想创建一个布尔掩码,为每第二次出现一个数字给出一个 true/1。我已经用循环完成了这个,但是实际的向量将包含数百万个元素,所以循环太慢了。我需要一个“矢量化”的解决方案。
这是一个示例向量:
101
102
103
101
104
102
101
103
101
104
这应该输出以下掩码:
0 (first occurrence of 101)
0 (first occurrence of 102)
0 (first occurrence of 103)
1 (second occurrence of 101)
0 (first occurrence of 104)
1 (second occurrence of 102)
0 (third occurrence of 101)
1 (second occurrence of 103)
1 (fourth occurrence of 101)
1 (second occurrence of 104)
【问题讨论】:
标签: matlab vector boolean vectorization