Faster way of writing this code: (finding index)
조회 수: 2 (최근 30일)
이전 댓글 표시
The code I want to optimize is:
index_min = sum( input > quantiles );
where quantiles is a vector of doubles in increasing order. I am using the sum function to find the index of quantiles that corresponds to the value of input. I think the "find" function is actually slower.
댓글 수: 2
Roger Stafford
2012년 12월 22일
Since the quantiles are in ascending order, it would likely be faster to use the 'histc' function with quantiles as the 'edges' vector and input as the first argument. The second returned argument (bin) would index the appropriate bin and thereby give you the index you seek.
Image Analyst
2012년 12월 22일
편집: Image Analyst
2012년 12월 22일
Just how much speed do you require? Is this for a real time app, like for video processing? How much slower? Are we talking nanoseconds here?
답변 (2개)
Matt Fig
2012년 12월 22일
That code does not return an index, but it does return the number of values in vector quantiles that are smaller than input.
댓글 수: 2
Walter Roberson
2012년 12월 22일
Because the values are in order, this is equivalent to returning the index of the last such value.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!