Rank: 9627 based on 0 downloads (last 30 days) and 0 files submitted
photo

Dru Franworth

E-mail

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Comments and Ratings by Dru View all
Updated File Comments Rating
10 Nov 2008 fastsearch Search an element in the array, or the next smaller and greater Author: Valentin Kuklin

I tried the following code in Matlab

clear all

x=randn(10000,1);

tic
for i=1:1000000
y=randn;
g=find(abs(x-y)==min(abs(x-y)));
end
toc
tic
y=sort(x);
for i=1:1000000
z=randn;
qq=fastsearch(y,z,1);
end
toc
----------------------------------------------------------------------------------

This is the output:
Elapsed time is 423.486252 seconds.
Elapsed time is 357.878006 seconds.

-----------------------------------------------------------------------------------
An improvement by 15%. Pretty impressive.

10 Nov 2008 fastsearch Search an element in the array, or the next smaller and greater Author: Valentin Kuklin

There is a slight bug in your code. In line 134 , you should have
index=fastsearch_indeed(array,von,m1-1,wert,bias);

Instead, you have fastsearch(array,von,m1-1,wert,bias);

Same thing for line 136. Basically, all you have to do is replace fastsearch in lines 134 and 136 with fastsearch_indeed.

09 Nov 2008 fastsearch Search an element in the array, or the next smaller and greater Author: Valentin Kuklin

I tried the following code and got an error message. As you can see, the number I am searching for is inside the sorted vector but it is generating an error message.

-----------------------------------------------------------------------------------

>> x=randn(10000,1);
>> y=sort(x);
>> z=randn;
>> fastsearch(y,z,1)
??? Error using ==> fastsearch
Too many input arguments.

Error in ==> fastsearch>fastsearch_indeed at 137
        index=fastsearch(array,m2+1,bis,wert,bias);

Error in ==> fastsearch at 59
index = fastsearch_indeed(array,1,length(array),wert,bias);

>> z

z =

    0.4291

>> min(y)

ans =

   -3.5758

>> max(y)

ans =

    4.0050

>> find(abs(y-z)==min(abs(y-z)))

ans =

        6694

Contact us at files@mathworks.com