Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand your question correctly, you want something like that:</p> <pre><code>&gt;&gt; p = polyfit([0 0.7],[0.1 1],1) p = 1.2857 0.1 &gt;&gt; figure &gt;&gt; hold on &gt;&gt; plot(x(y&gt;=p(1)*x+p(2)),y(y&gt;=p(1)*x+p(2)),'k.','MarkerSize',8) &gt;&gt; plot(x(y&lt;=p(1)*x+p(2)),y(y&lt;=p(1)*x+p(2)),'r.','MarkerSize',8) &gt;&gt; plot([0 0.7],[0.1 1],'g-') &gt;&gt; grid on,xlabel('x_1'),ylabel('x_2') </code></pre> <p>This is what I get in Octave:</p> <p><img src="https://i.stack.imgur.com/Uaaaq.jpg" alt="enter image description here"></p> <p><strong>EDIT following discussion in comments</strong>:</p> <p>There's not much more simplifying yo do, other than the following to make it more readable and debuggable in the future:</p> <pre><code>x = rand(500,1); y = rand(500,1); p = polyfit([0 0.7],[0.1 1],1); p2 = polyfit([0.4 1],[1 0],1); p3 = polyfit([0 1],[0.3 0.6],1); figure hold on plot(x,y,'m.','MarkerSize',8) idx1 = y&gt;=polyval(p,x) &amp; y&lt;=polyval(p2,x) &amp; y&gt;=polyval(p3,x); idx2 = y&gt;=polyval(p2,x) &amp; y&lt;=polyval(p,x) &amp; y&gt;=polyval(p3,x); idx3 = y&lt;=polyval(p3,x) &amp; y&lt;=polyval(p,x) &amp; y&lt;=polyval(p2,x); plot(x(idx1),y(idx1),'y.','MarkerSize',8) plot(x(idx2),y(idx2),'r.','MarkerSize',8) plot(x(idx3),y(idx3),'g.','MarkerSize',8) plot([0 0.7],[0.1 1],'k-') plot([0.4 1],[1 0],'k-') plot([0 1],[0.3 0.6],'k-') grid on,xlabel('x_1'),ylabel('x_2') </code></pre> <p>This results in the following figure:</p> <p><img src="https://i.stack.imgur.com/owOby.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload