function data_plot(data, t, x, y, C, R, colscheme)
% 
% Visualize data and clusters by projection
% on specified dimensions
%

if nargin < 7
  colscheme = 'rgb';
end
if nargin < 6
  R = 0.1;
end
if nargin < 5
  C = [];
end
if nargin < 4
  y = 3;
end
if nargin < 3
  x = 2;
end

[p,d] = size(data);
if (~isempty(C) & size(C,2) ~= d)
  error(['Wrong clusters set dimensions']);
end

if (~isempty(C))

  m = size(C,1);
  if all(size(R) == [1,1])
    R = R(ones(1,m),ones(1,d));
  elseif size(R,2) == 1
    R = R(:,ones(1,d))/sqrt(d);
  elseif size(R,1) == 1
    R = R(ones(1,m),:);
  end

  if (size(R,1) ~= m) | (size(R,2) ~= d)
    error(['Sizes of centers and radii matrixes are incompatible']);
  end

end

plot(data(t==0,x),data(t==0,y),[colscheme(2),'.']);
hold on;
plot(data(t==1,x),data(t==1,y),[colscheme(1),'.']);

if ~isempty(C)
  plot(C(:,x), C(:,y),[colscheme(3),'*']);

  for i = 1:size(C,1)
    circle(C(i,x),C(i,y),R(i,x),R(i,y));
  end
end
hold off;
refresh;

function circle(x, y, rx, ry)

t = -5:.1:5;
plot(x+rx*cos(pi*t/5),y+ry*sin(pi*t/5));

