-1

I have a question about matlab. It seems simple but I can't find the solution for inequalities linear region plot in matlab. For example, I want to plot the regions of y-x, and y>x and show the color for each one. For any x, y, but we can assume x = [-50:50].

Thank you.

I tried this one but don't know how to show the color for the third parameter.

[X,Y]=meshgrid(-1:0.01:1,-1:0.01:1); 
ineq1 = Y<X;
ineq2 = Y>X;
ineq3 = Y>-X;
colors = zeros(size(X))+ineq1+ineq2+ineq3;
scatter(X(:),Y(:),3,colors(:),'filled')
KL84
  • 237
  • 2
  • 4
  • 12
  • @Alan: I looked that one already, however the meshgrid doesn't have negative number. I just want to sketch y > x, y < x, y > -x and color them out...in the range [-50:50] for x – KL84 Mar 24 '14 at 03:15
  • 1
    @KL84 `meshgrid` can have negative numbers, just change the range of the grid. – Shai Mar 24 '14 at 07:47

1 Answers1

0
[X,Y]=meshgrid(-1:0.01:1,-1:0.01:1); 

x1=reshape(X,[size(X,1)*size(X,2) 1]);
y1=reshape(Y,[length(x1) 1]);
a=[x1 y1];

ineq1=a(a(:,1)>a(:,2),:);
ineq2=a(a(:,1)<a(:,2),:);
ineq3=a(-a(:,1)<a(:,2),:);

scatter(ineq1(:,1),ineq1(:,2),3,'b','filled');
hold on;
scatter(ineq2(:,1),ineq2(:,2),3,'r','filled');
scatter(ineq3(:,1),ineq3(:,2),3,'g','filled');
Guddu
  • 2,325
  • 2
  • 18
  • 23