Find for each value of a vector
Show older comments
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
Yao Li
on 16 Apr 2013
You'd better explain your work in details.
Walter Roberson
on 16 Apr 2013
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 ?
Answers (1)
Andrei Bobrov
on 16 Apr 2013
v = max(bsxfun(@times,bsxfun(@ge,X(:),Y(:)'),1:numel(Y))),[],2);
Categories
Find more on SimEvents in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!