Note that there are some explanatory texts on larger screens.

plurals
  1. POClassifying different points MATLAB
    text
    copied!<p>I have a random set of points that i want to plot into different classes (colours). I know how i can classify them according to different functions and I have shown an example below. The problem is that I know the classification regions I want, from (0,0.1) to (0.7,1) for example but i don't know what functions would achieve this or how to work them out.</p> <pre><code>x = rand(500,1); y = rand(500,1); g(:,1) = 1-x; g(:,2)= 1 -y; [~,la] = max(g'); % find the labels figure, hold on plot(x(la==1),y(la==1),'k.','MarkerSize',8) plot(x(la==2),y(la==2),'r.','MarkerSize',8) grid on,xlabel('x_1'),ylabel('x_2') </code></pre> <p>This is an example using some basic functions to create the plot below. At the moment I am using trial and error but how could I use the same idea as above but plotting regions where I know the endpoints like I mentioned above.</p> <p><img src="https://i.stack.imgur.com/d0GTI.png" alt="enter image description here"></p> <p>EDIT: Using am304 solution. I have got the correct output, but with a more complicated plot like this it seems like it could be simplified a lot.</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) plot(x(y&gt;=polyval(p,x) &amp; y&lt;=polyval(p2,x) &amp; y&gt;=polyval(p3,x)),y(y&gt;=polyval(p,x) &amp; y&lt;=polyval(p2,x) &amp; y&gt;=polyval(p3,x)),'y.','MarkerSize',8) plot(x(y&gt;=polyval(p2,x) &amp; y&lt;=polyval(p,x) &amp; y&gt;=polyval(p3,x)),y(y&gt;=polyval(p2,x) &amp; y&lt;=polyval(p,x) &amp; y&gt;=polyval(p3,x)),'r.','MarkerSize',8) plot(x(y&lt;=polyval(p3,x) &amp; y&lt;=polyval(p,x) &amp; y&lt;=polyval(p2,x)),y(y&lt;=polyval(p3,x) &amp; y&lt;=polyval(p,x) &amp; y&lt;=polyval(p2,x)),'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>
 

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