Find for each value of a vector

Is there a way to speed up of vectorize the following?
L=length(X)
v=1:L
for n=1:L
v(n)=find((X(n) >= Y), 1, 'last')
end
Thanks in advance.

2 Comments

You'd better explain your work in details.
I take it that Y is a vector?
Is there a reason you initialized v to 1:L instead of zeros(1,L) ?
What if x(n) is less than all Y ?

Sign in to comment.

Answers (1)

v = max(bsxfun(@times,bsxfun(@ge,X(:),Y(:)'),1:numel(Y))),[],2);

Categories

Tags

Asked:

on 16 Apr 2013

Community Treasure Hunt

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

Start Hunting!