Function faster than find?

2 次查看(过去 30 天)
Jared
Jared 2013-4-8
I use the find command compare 2 vectors of time, one with a much higher rate than the other. Say vector1=[1 2 3 4 5], vector2 many be [1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.2 2.3 3.1...], but vector2 has an irregular pattern.
What I want to do is find the number of values of vector2 that occur between each point of vector1. So betweem 1 and 2 of vector1, I have 9 values (1.1-1.9). I also want the index of the first value (1.1) which would be 1.
For the second case, between 2 and 3 of vector1, I have 2 values, and the index of the first of those values is 10.
I use the following code to do this:
for i=1:length(vector1)-1
index=find(vector1(i)<=vector2 & vector2<vector1(i+1),1,'first');
count=length(find(vector1(i)<=vector2 & vector2<vector1(i+1)));
end
This turns out to be extremely slow with typical vector lengths of vector1 around 200,000 and vector2 of 1,500,000.
Any tips on ways to speed this up, or another function? Another way to look at it is vector1 is providing the bins, and vector2 has the values that fall in each bin. I want the number in each bin, and the index of the first value in each bin. I tried histc but wasn't happy with how it was working.

回答(1 个)

per isakson
per isakson 2013-4-9
编辑:per isakson 2013-4-9
Hint:
doc histc

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by