From: NIcholas on 7 Jun 2010 11:59 I have a vector A and I want to search A for the first value larger than some constant c, starting at index i. Is there a quicker way than the following command? find(A(i:end)>c,1,'first') I assume that it is copying the array A(i:end) and then doing the computation, which will be slow if the first element is very close to the front. Thanks, Nick
From: Bruno Luong on 7 Jun 2010 12:26 "NIcholas " <dsfadfa(a)aol.com> wrote in message <huj50b$pq5$1(a)fred.mathworks.com>... > I have a vector A and I want to search A for the first value larger than some constant c, starting at index i. > > Is there a quicker way than the following command? > find(A(i:end)>c,1,'first') > > I assume that it is copying the array A(i:end) and then doing the computation, which will be slow if the first element is very close to the front. I can only think of mexing. More generally, you could use the solution proposes here http://www.mathworks.com/matlabcentral/fileexchange/24576-inplacearray-a-semi-pointer-package-for-matlab function testfind(i) A=rand(1,1e7); tic; find(A>0.5,1,'first'); toc % Elapsed time is 0.055850 seconds. tic; find(A(i:end)>0.5,1,'first'); toc % Elapsed time is 0.151338 seconds. tic; ai=inplacearray(A,i); find(ai>0.5,1,'first'); releaseinplace(ai); toc %Elapsed time is 0.063139 seconds. end % Bruno
|
Pages: 1 Prev: Simulink Air Compressor Model Next: Displaying waiting msg until the process is finished |