Home vectorising multiple calls of Matlab 'find'
Reply: 0

vectorising multiple calls of Matlab 'find'

user8034 Published in September 21, 2018, 8:04 am

I make a large number of calls to the 'find' function of Matlab. For example, the following should give the essence:

for i=1:10^8
    indx(i) = find([0.2, 0.52, 0.76,1] < x(i), 1, 'last');

Is there a way to vectorize this code to speed it up? Just including x as a vector creates an error. If vectorization is not possible, then any other suggestions for speed would be appreciated. The actual problem I wish to solve has a considerably longer vector in the place of [0.2, 0.52, 0.76,1], so any solution shouldn't depend on the specific vector I provided.


share|improve this question
  • 2
    With that example the result is always 4. Are you sure you want 'last'? – Luis Mendo Feb 14 at 0:54
  • right....I've flipped the inequality (in my recent edit) to make it non-trivial. Just trying to construct a toy problem that captures the real issue in a simple way. Thanks for spotting it. – physioConfusio Feb 14 at 1:03
  • 1
    Caveat: your loop will give error if the inequality doesn't satisfy for x. Try it with any value in x less than 0.2 – Sardar Usama Feb 14 at 4:44

3 Answers 3

active oldest votes
up vote 3 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.363917 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO