Faster way of writing this code: (finding index)

3 vues (au cours des 30 derniers jours)
Evan
Evan le 22 Déc 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.
  2 commentaires
Roger Stafford
Roger Stafford le 22 Déc 2012
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
Image Analyst le 22 Déc 2012
Modifié(e) : Image Analyst le 22 Déc 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?

Connectez-vous pour commenter.

Réponses (2)

Matt Fig
Matt Fig le 22 Déc 2012
That code does not return an index, but it does return the number of values in vector quantiles that are smaller than input.
  2 commentaires
Walter Roberson
Walter Roberson le 22 Déc 2012
Because the values are in order, this is equivalent to returning the index of the last such value.
Matt Fig
Matt Fig le 22 Déc 2012
Yes, it will return the last value. How large is quantiles?

Connectez-vous pour commenter.


Matt J
Matt J le 23 Déc 2012

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by