Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
optimizing algorithm

Subject: optimizing algorithm

From: MICHAEL

Date: 2 Oct, 2010 08:14:09

Message: 1 of 2

i have matrix (MAP) which elements are the x and y coordinates of walls locations
the aim of the code is to check how many walls
when i run the code on big matrix, the bottleneck is at strmatch function
how to improve the code so it will be more faster?


if (Tx.Y ~= Rx.Y)
    % Let Rx > Tx
    if (Tx.Y > Rx.Y)
        [Tx, Rx] = SwapPoint ( Tx, Rx);
    end
    if (Tx.X == Rx.X)
        for Yi=Tx.Y + 1 : Rx.Y
            indx=strmatch([Tx.X Yi], MAP);
            if (~isempty(indx))
                WallsPass=[WallsPass; Tx.X, Yi];
                LossesPass=[LossesPass defaultWallLose];
            end
        end
    else
        m = (Tx.Y - Rx.Y)/(Tx.X - Rx.X);
        for Yi=Tx.Y + 1 : Rx.Y
            Xi = floor(Tx.X+0.5 + (Yi - Tx.Y - 0.5)/m);
            indx=strmatch([Xi Yi], MAP);
            if (~isempty(indx))
                WallsPass=[WallsPass; Xi, Yi];
                LossesPass=[LossesPass defaultWallLose];
            end
        end
    end
end

Subject: optimizing algorithm

From: Janis Doebler

Date: 7 Oct, 2010 11:16:05

Message: 2 of 2

> i have matrix (MAP) which elements are the x and y coordinates of walls locations
> when i run the code on big matrix, the bottleneck is at strmatch function
strmatch is for finding strings, isn't it? So, why is it used for a matrix here? Or is it a cell-array? How are the coordinates stored in MAP?
Well, more information about MAP is needed. Do you need strings, or does it work with logical variables?


> the aim of the code is to check how many walls
How does this sentence end?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us