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

vectorising multiple calls of Matlab 'find'

user670
1#
user670 Published in June 18, 2018, 7:19 am

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

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

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.

thanks.

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO