-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotgrid.m
53 lines (47 loc) · 1.13 KB
/
plotgrid.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
51
52
53
function varargout = plotgrid(n,d,options)
% PLOTGRID Plot the sparse grid
% PLOTGRID(N,D) Plots the sparse grid points of dimension D = 2
% or D = 3 up to level N.
%
% PLOTGRID(N,D,OPTIONS) Plots as above, but with default grid
% type replaced by the grid type specified in OPTIONS, an
% argument created with the SPSET function. See SPSET for
% details.
%
% H = PLOTGRID(...) Returns a vector of handles to the grid points
% (useful for changing the look of the plotted grid).
if nargin ~= 2 && nargin ~= 3
error(['Wrong number of arguments. Please see ''help plotgrid''' ...
' for usage information.']);
end
if nargin < 3, options = []; end
holdstate = ishold;
h = [];
switch d
case 2
for k = 0:n
x = spgrid(k,2,options);
th = plot(x(:,1),x(:,2),'k.');
h = [h; th];
axis equal;
axis([0 1 0 1]);
hold on;
end
case 3
for k = 0:n
x = spgrid(k,3,options);
th = plot3(x(:,1),x(:,2),x(:,3),'k.');
h = [h; th];
axis equal;
axis([0 1 0 1 0 1]);
hold on;
end
otherwise
error(['Invalid parameter d = ' num2str(d) '.']);
end
if ~holdstate
hold off;
end
if nargout > 0
varargout{1} = h;
end