title: Matlab point in polygon
body: <p>Hi found this code on this <a href="https://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test">list</a> and need help converting it to Matlab.</p>
  
  <pre><code>int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
  {
    int i, j, c = 0;
    for (i = 0, j = nvert-1; i &lt; nvert; j = i++) {
      if ( ((verty[i]&gt;testy) != (verty[j]&gt;testy)) &amp;&amp;
       (testx &lt; (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
         c = !c;
    }
    return c;
  }
  </code></pre>
  
  <p><strong>nvert</strong>: Number of vertices in the polygon. Whether to repeat the first vertex at the end.</p>
  
  <p><strong>vertx, verty</strong>: Arrays containing the x- and y-coordinates of the polygon's vertices.</p>
  
  <p><strong>testx, testy</strong>: X- and y-coordinate of the test point. (This is from another Stack Overflow question: <a href="https://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test">Point in Polygon aka hit test</a>.</p>
  
  <p><strong><em>JavaScript version:</em></strong></p>
  
  <pre><code>function insidePoly(poly, pointx, pointy) {
      var i, j;
      var inside = false;
      for (i = 0, j = poly.length - 1; i &lt; poly.length; j = i++) {
          if(((poly[i].y &gt; pointy) != (poly[j].y &gt; pointy)) &amp;&amp; (pointx &lt; (poly[j].x-poly[i].x) * (pointy-poly[i].y) / (poly[j].y-poly[i].y) + poly[i].x) ) inside = !inside;
      }
      return inside;
  }
  </code></pre>
  
  <p>How will this translate in <strong>Matlab</strong>:</p>
  
  <pre><code>function insidePoly = inpoly(poly, pointx, pointy)
  % Code
  % return inside
  </code></pre>