-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspread.m
37 lines (35 loc) · 879 Bytes
/
spread.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
function spread(X, label)
% Plot samples of different labels with different colors.
% Written by Michael Chen ([email protected]).
[d,n] = size(X);
if nargin == 1
label = ones(n,1);
end
assert(n == length(label));
color = 'brgmcyk';
m = length(color);
c = max(label);
figure(gcf);
clf;
hold on;
switch d
case 2
view(2);
for i = 1:c
idc = label==i;
% plot(X(1,label==i),X(2,label==i),['.' color(i)],'MarkerSize',15);
scatter(X(1,idc),X(2,idc),36,color(mod(i-1,m)+1));
end
case 3
view(3);
for i = 1:c
idc = label==i;
% plot3(X(1,idc),X(2,idci),X(3,idc),['.' idc],'MarkerSize',15);
scatter3(X(1,idc),X(2,idc),X(3,idc),36,color(mod(i-1,m)+1));
end
otherwise
error('ERROR: only support data of 2D or 3D.');
end
axis equal
grid on
hold off