在IDL阵列范围内找到?

时间:2019-11-22 02:41:37

标签: matlab idl-programming-language

我试图在数组A中查找所有索引,其中值大于time0且小于time1。在matlab中,我可以这样做:

[M,F] = mode(  A((A>=time0) & (A<=time1))  ) %//only interested in range

我在IDL中有类似的东西,但是速度很慢:

tmpindex0 = where(A ge time0)   
tmpindex1 = where(A lt time1)   
M = setintersection(tmpindex0,tmpindex1)  

其中setintersection()是函数,用于查找两个数组之间的相交元素。什么是快速的替代实现?

2 个答案:

答案 0 :(得分:1)

您可以结合您的条件:

M = where(A ge time0 and A lt time1, count)

然后M将包含指向time0time1的索引,而count将包含索引的数目。通常,您要在使用count之前先检查M

答案 1 :(得分:0)

这有效(来自mgalloy答案的轻微修改):

M = where( (A ge time0) and (A lt time1), n_match, complement=F, n_complement=ncomp)

括号分隔不是必需的,但可以增加清晰度。 n_match包含与您的条件匹配的数量,而补语F将包含不匹配的索引,而ncomp将包含不匹配的数量。

相关问题