function h=circleplot(x,y,z,zmin,zmax,col)
%CIRCLEPLOT.m plots z=f(x,y) as circles of size proportional to z
%
% h=circleplot(x,y,z,zmin,zmax,col)
%
%Indicates the value of z at locations (x,y) using circles with
%diameter proportional to z.  The values zmin and zmax allow the
%user to specify the range of z values.  Col is a colorspec 
%defining the color of the circles.
%

%1. check inputs

n=length(x);
if(length(y)~=n);
	error('x and y must be the same length');
end
if(length(z)~=n);
	error('x and z must be the same length');
end

%2. convert z into sizes
sz1=2;%smallest size of circle for this system
sz2=20;%largest size of circle for this system

sz=interp1([zmin;zmax],[sz1;sz2],z);%convert z to circle sizes

I=find(z<zmin);  %set values of z < zmin to smallest size
if(~isempty(I));sz(I)=sz1;end
I=find(z>zmax);	%set values of z > zmax to largest size
if(~isempty(I));sz(I)=sz2;end


h=zeros(n,1);%allocate space for handles
for j=1:n
	h(j)=plot(x(j),y(j),'ko','markerfacecolor',col, 'markersize',sz(j));hold on
end



