Rank: 3474 based on 19 downloads (last 30 days) and 1 file submitted
photo

Valentin Kuklin

E-mail

Personal Profile:

Professional Interests:

 

Watch this Author's files

 

Files Posted by Valentin
Updated   File Tags Downloads
(last 30 days)
Comments Rating
09 Dec 2008 fastsearch Search an element in the array, or the next smaller and greater Author: Valentin Kuklin search, array, equal, smaller, greater, interpolation 19 8
  • 4.5
4.5 | 2 ratings
Comments and Ratings on Valentin's Files View all
Updated File Comment by Comments Rating
10 Nov 2008 fastsearch Search an element in the array, or the next smaller and greater Author: Valentin Kuklin Franworth, Dru

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 Franworth, Dru

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 Franworth, Dru

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

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

Hi Alexander,

thanks for your notes.

I think there is no bug. This code with "Check if wert is inside of array." is used only for the first run, for example if you have array=1:1:100 and you search -5 or 105. For the further runs it does not play any role, the searched number will be anyway within [von, bis]. Actually it can not be infinite recursion because every "if" ends with "return" but not with the new call of function.

But anyway I am happy that someone uses my function and tries to find bugs :) Thanks again :)

Valentin Kuklin

05 May 2008 fastsearch Search an element in the array, or the next smaller and greater Author: Valentin Kuklin Chemeris, Alexander

It's good that such a useful algorithm in finally implemented in Matlab :)
But this implementation have a bug. "Check if wert is inside of array." should looks like:

if wert<array(von)
    if bias==1
        index=von;
        return;
    else
        index=-1;
        return;
    end
end
if wert>array(bis)
    if bias == -1
        index = bis;
        return;
    else
        index = -1;
        return;
    end
end

That is "von" and "bis" are used instead of "1" and "end". Without this fix algorthm may enter infinite recursion in certain cases.

Top Tags Applied by Valentin
approximation, array, element, equal, fastsearch
Files Tagged by Valentin
Updated   File Tags Downloads
(last 30 days)
Comments Rating
09 Dec 2008 fastsearch Search an element in the array, or the next smaller and greater Author: Valentin Kuklin search, array, equal, smaller, greater, interpolation 19 8
  • 4.5
4.5 | 2 ratings
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com