function plotfn(data,centers,f,res,varargin)
% function plotfn(data,centers,f,res,params...)
%
% plots f which should take a matrix of row vectors of two variables (x and y)
% [thus this argument to f is nx2] and the parameters at the end of plotfn
% and returns a column vector of values
%
% The resolution of the plot is controlled by res.  The range of the
% plot is controlled by the data and centers.  The data and centers
% are plotted on the x-y plane for reference.
%
% as an example... to plot the parabola defined by the function bowl
% one would call plotfn(trainx,centers,'bowl',1,eye(2))

mins = min(min(data),min(centers));
maxs = max(max(data),min(centers));

X = [mins(1):res:maxs(1)]';
Y = mins(2):res:maxs(2);
nxpts = size(X,1);
nypts = size(Y,2);
X = repmat(X,1,nypts);
Y = repmat(Y,nxpts,1);
pts = [reshape(X,nxpts*nypts,1) reshape(Y,nxpts*nypts,1)];
Z = feval(f,pts,varargin{:});
Z = reshape(Z,nxpts,nypts);

% plot the 3D mesh:
mesh(X,Y,Z);
% try this one instead if the 3D plot is blocking your view of the centers
% contour(X,Y,Z); 

hold on
% colormap([0 0 0]); % set colormap to all black -- change here for something
		% more elaborate -- remove this to get the colormap to 
		% match the height of the graph
hold on;
plot(data(:,1),data(:,2),'gx');
plot(centers(:,1),centers(:,2),'ro');
hold off;
