|
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
|