From: Dmitriy on 2 Feb 2010 12:57 Have two sorted arrays DTime (size N~6000) and T (~ size 20*N) For each element i in DTime want to find the last element j in T s.t. DTime(i) >T(j) I can solve this task with for i=1:length(DTime) res(i)=find(DTime(i)>T,1)-1; end However, it is inefficient, as on each iteration a large matrix T is passed to find(). This problem is pretty standard. I wonder if there is a better solution? PS: I ran an experiment. Seems that size of T is the main slowing factor for find() A=zeros(1,10000000);A(1,5)=1; tic for i=1:100; find(A==1,1);end toc tic for i=1:100; find(A==1);end toc %% A(1,5)=0;A(1,5000000)=1; tic for i=1:100; find(A==1,1);end toc %% A=zeros(1,5000000);A(1,5000000)=1; tic for i=1:100; find(A==1,1);end toc Elapsed time is 2.144091 seconds. Elapsed time is 2.770985 seconds. Elapsed time is 2.502952 seconds. Elapsed time is 1.894031 seconds.
|
Pages: 1 Prev: Matlab smooth function - implementation of loess Next: Ellipse detection code |