help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: iterative comparison


From: Ted Harding
Subject: RE: iterative comparison
Date: Tue, 10 Jun 2003 18:16:12 +0100 (BST)

On 10-Jun-03 E2 wrote:
> Howdy all, 
> I've got an array of positions pos = [x1,y1;x2,y2;....] and
> an array of obstacles obs = [x1,y1;x2,y2;...] and I'd like to
> know the positions that are within some threshold of an obstacle.
> 
> <background>
> the positon array describes the path of a robot, and the obstacle
> array describes obstacle positions.  I want to know when the robot
> impacted with an obstacle (i.e. came within some threshold) so
> I can calculate a reward for reinforcement learning.
> </background>
> 
> I know I could do it with for loops basically doing:
> 
> for i 
> for j
>       if(norm(pos(i,:) - obs(j,:)) < thresh)
>               impacts ++;

Px=pos(:,1); Py=pos(:,2); Ox=obs(:,1); Oy=obs(:,2); #these are col vectors
Ux=Px*ones(1,length(Ox)); Vx=ones(length(Px),1)*Ox' ;
Uy=Py*ones(1,length(Oy)); Vy=ones(length(Py),1)*Oy' ;
Dx = Ux-Vx; Dy = Uy-Vy;

seps = sqrt(Dx.^2 + Dy.^2);
# gives matrix (s_ij) of separations between position(i) and obstacle(j)

impacts = sum(sum(seps < thresh));

Try that (hoping I haven't made any slips)!
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 167 1972
Date: 10-Jun-03                                       Time: 18:16:12
------------------------------ XFMail ------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]