Faster way of writing this code: (finding index)

8 views (last 30 days)
Evan on 22 Dec 2012
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.
Image Analyst
Image Analyst on 22 Dec 2012
Edited: Image Analyst on 22 Dec 2012
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?

Sign in to comment.

Answers (2)

Matt Fig
Matt Fig on 22 Dec 2012
That code does not return an index, but it does return the number of values in vector quantiles that are smaller than input.
Matt Fig
Matt Fig on 22 Dec 2012
Yes, it will return the last value. How large is quantiles?

Sign in to comment.

Matt J
Matt J on 23 Dec 2012

Community Treasure Hunt

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

Start Hunting!

Translated by