开发者

Speed Enhancements for a Sorted Vector in MATLAB

开发者 https://www.devze.com 2023-04-12 03:49 出处:网络
What is the fastest way to lookup the index of a value in sorted vector in MATLAB? That is, is there a fast find(vector == myNumber, 1, \'first\') for whe开发者_如何学Gon vector is sorted?

What is the fastest way to lookup the index of a value in sorted vector in MATLAB? That is, is there a fast find(vector == myNumber, 1, 'first') for whe开发者_如何学Gon vector is sorted?

I have a large matrix (200,000 x 4) of locations each with a unique integer ID recorded in the first column. I want to find the right the location of a known ID but thousands of searches can take me a little bit to find.


If you use ismembc2, the loc output should give you what you need. See this for more details:

http://www.mathworks.com/support/solutions/en/data/1-9NIE1N/index.html?product=ML&solution=1-9NIE1N


There are a number of submissions for this on FEX: http://www.mathworks.com/matlabcentral/fileexchange/?term=binary+search+vector


I do not know if it is faster but you may want to try

result=vector(vector(:,1)==myNumber,:)

result will contain the 4 elements row for which vector first column == myNumber

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号