samer@47
|
1 function H=scat(x,varargin)
|
samer@47
|
2
|
samer@47
|
3 % SCAT: 2D/3D scatter plot using dots
|
samer@47
|
4 % Usage: h=scat(x,...)
|
samer@47
|
5 %
|
samer@47
|
6 % x - matrix of 2D or 3D points
|
samer@47
|
7 % h - returns handle graphics object
|
samer@47
|
8 %
|
samer@47
|
9 % Valid options
|
samer@47
|
10 % 'perspective'::(0|1)/1 ~'use perspective projection in 3D'
|
samer@47
|
11 % 'axis'::(0|1)/1 ~'remove axes if 0'
|
samer@47
|
12 % 'box' ::(0|1)/1 ~'enable/disable axis box'
|
samer@47
|
13 % 'marker'::string ~'standard matlab marker code'
|
samer@47
|
14 % 'plotargs'::cell{} ~'extra arguments to plot'
|
samer@47
|
15 %
|
samer@47
|
16 % In 3D, sets up axes so that shapes are right.
|
samer@47
|
17
|
samer@47
|
18 if isa(x,'data'), x=double(x); end
|
samer@47
|
19
|
samer@47
|
20 marker=get(gca,'DefaultLineMarker');
|
samer@47
|
21 if strcmp(marker,'none'), marker=get(gcf,'DefaultLineMarker'); end
|
samer@47
|
22 if strcmp(marker,'none'), marker=get(0,'DefaultLineMarker'); end
|
samer@47
|
23 if strcmp(marker,'none'), marker='+'; end
|
samer@47
|
24 opts=prefs('perspective',1,'axis',1,'box',1,'marker',marker, ...
|
samer@47
|
25 'plotargs',{},varargin{:});
|
samer@47
|
26 if size(x,2)<=4 && size(x,1)>8, x=x'; end
|
samer@47
|
27
|
samer@47
|
28 if isfield(opts,'markersize'),
|
samer@47
|
29 opts.plotargs=[{'MarkerSize',opts.markersize},opts.plotargs];
|
samer@47
|
30 end
|
samer@47
|
31
|
samer@47
|
32 if (size(x,1)>=3),
|
samer@47
|
33 h=plot3(x(1,:),x(2,:),x(3,:),opts.marker,opts.plotargs{:});
|
samer@47
|
34 if opts.perspective, camproj('perspective'); end
|
samer@47
|
35 axis equal;
|
samer@47
|
36 axis vis3d;
|
samer@47
|
37 elseif ~isempty(x)
|
samer@47
|
38 h=plot(x(1,:),x(2,:),opts.marker,opts.plotargs{:});
|
samer@47
|
39 else
|
samer@47
|
40 h=[];
|
samer@47
|
41 end
|
samer@47
|
42
|
samer@47
|
43 %set(gca,'DrawMode','fast');
|
samer@47
|
44 %set(gcf,'Renderer','painters');
|
samer@47
|
45 if (nargout>0), H=h; end
|
samer@47
|
46
|
samer@47
|
47 if ~opts.box, box off; else; box on; end
|
samer@47
|
48 if ~opts.axis, axis off; end
|