```Path: news.mathworks.com!not-for-mail
From: "Damian Sheehy" <Damian.Sheehy@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Logicals, winding number, -inpolgon
Date: Fri, 20 Mar 2009 11:23:25 -0400
Organization: The MathWorks, Inc.
Lines: 35
Message-ID: <gq0cdf\$5b2\$1@fred.mathworks.com>
References: <gq085l\$bpd\$1@fred.mathworks.com>
Reply-To: "Damian Sheehy" <Damian.Sheehy@mathworks.com>
NNTP-Posting-Host: sheehyd.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1237562607 5474 144.212.105.140 (20 Mar 2009 15:23:27 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 20 Mar 2009 15:23:27 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:526449

Zeinab,

You simply use "logical indexing". Read the example given in the
help for INPOLYGON.
% Self-intersecting polygon
xv = rand(6,1); yv = rand(6,1);
xv = [xv ; xv(1)]; yv = [yv ; yv(1)];
x = rand(1000,1); y = rand(1000,1);
in = inpolygon(x,y,xv,yv);
plot(xv,yv,x(in),y(in),'.r',x(~in),y(~in),'.b')

The coordinates you are looking for are given by x(in), y(in)

Damian

"Zeinab Al-Rekabi" <nospam-rekabi570@yahoo.ca> wrote in message
news:gq085l\$bpd\$1@fred.mathworks.com...
> Hello
>
> I am trying to compute the winding number, which is the number of times
> that a closed curve encircles the point.
> I used the matlab function [IN]=inpolygon(X,Y,xv,yv), where X,Y are the
> points and xv,yv are the curves coutour (assuming 2d).
>
> I obtain a logical array nX1, which has 0s and 1s. 0s being outside the
> countour and 1s being inside the contour. My question: how do I convert
> such a logical array into the X,Y numbers which it originally was, so
> baiscally for those values that were 1, how do I get their X,Y values? Is
> there a matlab function that does this conversion and if not may anyone
> assist me in obtaining them.
>
> Thank you kindly
> Z

```