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

Yao Li
Yao Li 2013년 4월 16일
You'd better explain your work in details.
Walter Roberson
Walter Roberson 2013년 4월 16일
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 ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 4월 16일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 SimEvents에 대해 자세히 알아보기

태그

질문:

2013년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by