-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathppatterns2.m
158 lines (137 loc) · 4.36 KB
/
ppatterns2.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
function varargout=ppatterns2(data,arg1='',arg2='')
% PPATTERNS Plots pattern as points in feature space.
%
% Synopsis:
% ppatterns(data,marker_size)
% ppatterns(data,'num')
% ppatterns(X,marker,marker_size)
% ppatterns(X,y)
% ppatterns(X,y,marker_size)
% ppatterns(X,y,'num')
%
% Description:
% ppatterns(data,marker_size) plots data.X as points
% distinguished by marker and its color according to
% given labels data.y. The marker size can be prescribed.
%
% ppatterns(data,'num') plots data.X in distinguished
% by numbers and colors according to given labels data.y.
% The marker size can be determined by argument marker_size.
%
% ppatterns(X,marker,marker_size) plots data X. Marker type
% can be determined by argument marker. The marker size can
% be determined by argument marker_size.
%
% ppatterns(X,y,...) instead of structure data, which contains
% items X and y these can enter the function directly.
%
% If dimension of input data is greater than 3 then
% only first 3 dimensions are assumed and data are plotted
% in 3D space.
%
% Output:
% H [struct] Handles of used graphical objects.
%
% Example:
% data = load('riply_trn');
% figure; ppatterns(data);
% figure; ppatterns(data,'num');
% figure; ppatterns(data.X,'xk',10);
%
% See also
% PLINE.
%
% About: Statistical Pattern Recognition Toolbox
% (C) 1999-2003, Written by Vojtech Franc and Vaclav Hlavac
% Czech Technical University Prague
% Faculty of Electrical Engineering
% Center for Machine Perception
% Modifications:
% 25-may-2004, VF
% 11-mar-2004, VF,
% 5-oct-2003, VF, returns handles
% 12-feb-2003, VF, 1D, 3D added
% 7-jan-2003, VF, created
oldhold = ishold;
hold on;
% takes care of the case when X,y is used insted of structure data
% ppatterns(X,y,...) -> ppatterns(data,...)
if nargin > 1 & ~isstruct(data) & size(data,2)==length(arg1) & ~ischar(arg1),
data.X=data;
data.y=arg1;
if nargin >= 3, H=ppatterns(data,arg2); else H=ppatterns(data); end
if nargout >= 1, varargout{1}=H; end
return;
end
% ppatterns(data) or ppatterns(data,marker_size)
if isstruct(data) == 1 & (nargin < 2 | ischar(arg1)==0),
if nargin < 2, marker_size = 6; else marker_size = arg1; end
H = [];
for i = min(data.y):max(data.y),
inx = find(data.y == i);
if ~isempty(inx),
if size(data.X,1)==1,
h = plot(data.X(1,inx),zeros(1,length(inx)),marker_type2(i));
elseif size(data.X,1)==2,
h = plot(data.X(1,inx),data.X(2,inx),marker_type2(i));
else
h = plot3(data.X(1,inx),data.X(2,inx),data.X(3,inx),marker_type2(i));
end
set(h,'Color',marker_color2(i));
set(h,'MarkerSize',marker_size);
H = [H, h];
end
end
% ppatterns(data,marker)
elseif isstruct(data) == 1 & nargin == 2 & ischar(arg1)==1 & strcmpi(arg1,'num'),
marker_size = 12;
H_Points = [];
H_Num = [];
for i = min(data.y):max(data.y),
inx = find(data.y==i);
if ~isempty(inx),
if size(data.X,1)==1,
h = plot(data.X(1,inx),zeros(1,length(inx)),'o');
elseif size(data.X,1)==2,
h = plot(data.X(1,inx),data.X(2,inx),'o');
else
h = plot3(data.X(1,inx),data.X(2,inx),data.X(3,inx),'o');
end
set(h,'Color',marker_color2(i));
set(h,'MarkerSize',marker_size);
H_Points = [H_Points, h ];
if size(data.X,1)==1,
h = text(data.X(1,inx),zeros(1,length(inx)),num2str(i));
elseif size(data.X,1)==2,
h = text(data.X(1,inx),data.X(2,inx),num2str(i));
else
h = text(data.X(1,inx),data.X(2,inx),data.X(3,inx),num2str(i));
end
set(h,'HorizontalAlignment','center');
set(h,'VerticalAlignment','middle');
set(h,'Color',marker_color2(i));
set(h,'FontSize',marker_size-2);
H_Num = [H_Num, h(:)'];
end
end
H = [H_Points, H_Num];
else
if nargin < 2, marker = 'kx'; else marker = arg1; end
if nargin < 3, marker_size = 6; else marker_size = arg2; end
if size(data,1)==1,
h = plot(data(1,:),zeros(1,size(data,2)),marker);
elseif size(data,1)==2,
h = plot(data(1,:),data(2,:),marker);
else
h = plot3(data(1,:),data(2,:),data(3,:),marker);
end
H = h;
set(h,'MarkerSize',marker_size);
end
if oldhold,
hold on;
else
hold off;
end
if nargout>=1, varargout{1} = H; end
return;