-
Notifications
You must be signed in to change notification settings - Fork 0
/
ineqplot.m
50 lines (50 loc) · 1.52 KB
/
ineqplot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function h = ineqplot(I,R,c)
% Plotting inequalities, simple and easy.
%
% Input arguments
% I - Inequality as string, i.e. 'x+y>10'
% R - Vector of four components defined by: [xmin, xmax, ymin, ymax],
% if two components are passed: [min, max], the defined region
% will be a square and xmin=ymin=min, xmax=ymax=max.
% c - A three-element RGB vector, or one of the MATLAB
% predefined names, specifying the plot color.
%
% Output arguments
% h - returns the handle of the scattergroup
% object created.
%
% Examples:
% >> ineqplot('x.^2+y.^2<10',[-5 5], 'r');
% >> h = ineqplot('y<x+3',[0 10 -5 5]);
% >> set(h,'MarkerFaceColor','r'); % Change color
%
%
% $ Author: Jorge De Los Santos $
% $ Version: 0.1.0 (initial version) $
%
% Deafault color
if nargin<3, c='b'; end; % blue default
% Length of R vector
if length(R)==4
xmin = R(1); xmax = R(2);
ymin = R(3); ymax = R(4);
elseif length(R)==2
xmin = R(1); xmax = R(2);
ymin = R(1); ymax = R(2);
end
% hold
set(gca,'NextPlot','add');
% Limits
axis([xmin xmax ymin ymax]);
% Number of points (Change N value for more resolution)
N = 150;
dx=(xmax-xmin)/N; %
dy=(ymax-ymin)/N;
[x,y]=meshgrid(xmin:dx:xmax, ymin:dy:ymax);
% Eval condition
idx = find(~eval(I));
x(idx) = NaN; %#ok
h = plot(x(:),y(:),c,...
'LineStyle','.',...
'MarkerSize',1);
end