Click here to Skip to main content
15,891,248 members

Comments by Moharram (Top 9 by date)

Moharram 28-Sep-22 0:57am View    
I attached the implementation
Moharram 28-Sep-22 0:57am View    
I attached the implementation
Moharram 28-Sep-22 0:56am View    
OK, Thanks
Moharram 24-Sep-22 12:04pm View    
Deleted
here is my implementation in Delphi:

TOutput2 = record
  Flag,Index : TBordar_Int32;
end;

function TMatlab.IsMember(const A, B: TBordar_Double): TOutput2;
var
    i : Integer;
    j : Integer;
    k : Integer;
    Index,Flag : TBordar_Int32;
begin
    SetLength(Index, Length(A));
    SetLength(Flag,Length(A));

    for i := 0 to Length(A) - 1 do
    begin

        for j := 0 to Length(B) - 1 do
        begin
            Flag[i] := 0;

            if A[i] = B[j] then
            begin
                Flag[i] := 1;
                Index[k] := j;
                inc(k);
                break;

            end;

            Flag[i] := 0;

        end;
    end;

    SetLength(Index,k);
    Result.Flag := Flag;
    Result.Index := Index;


end;



in this version, i changed the search algorithm to Binaray Search:

function TMatlab.IsMember2(A, B: TBordar_Double): TOutput2;
var
    i : Integer;
    j : Integer;
    k : Integer;
    Index,Flag : TBordar_Int32;
    Len : Integer;
    res : Integer;

    function bsearch(const v : Double) : Integer;
    var
        nlo,nhi,t : Integer;
    begin
        nlo := 0;
        nhi := Len-1;

        while nlo <> nhi do
        begin
            t := (nhi+nlo) div 2;

            if B[t] < v then
                nlo := t+1
            else
                nhi := t;
        end;

        if B[nhi]=v then
            result := nhi
        else
            result := -1;
    end;
begin
    SetLength(Index, Length(A));
    SetLength(Flag,Length(A));
    Len :=  Length(B);
    k := 0;

    for i := 0 to Length(A) - 1 do
    begin
        res := bsearch(A[i]);

        if res = -1 then
            Flag[i] := 0
        else
        begin
            Flag[i] := 1;
            Index[k] := j;
            inc(k);
        end;
    end;

    SetLength(Index,k);
    Result.Flag := Flag;
    Result.Index := Index;

end;


however the second version gets faster than first version, but Matlab version is faster yet.

thank you
Moharram 31-Oct-13 7:09am View    
thanks to WuRunZhe and his guide on this page:

http://www.cplusplus.com/forum/windows/33960

i solved this problem by using SetFocus on WM_MOUSEMOVE. then the control can get the WM_MOUSEWHEEL.