%function [] = signal_vs_position(positions, data, style, export, exportname);
% takes a 2xN list of X,Y coordinates (positions) and a 1xN list of
% Z values (data) and displays a 3-D map of the data.
%
% function should be called with style==1 and export==0, which will
% display a solid surface and not export the image to a file
%
% Written by Greg Porreca (Church Lab), 01-19-2006
%
function [] = signal_vs_position(positions, data, style, export, exportname);

figure;

xlin = linspace(min(positions(:,1)), max(positions(:,1)));
ylin = linspace(min(positions(:,2)), max(positions(:,2)));

[X, Y] = meshgrid(xlin, ylin);

z = griddata(double(positions(:,1)), double(positions(:,2)), double(data), X, Y, 'cubic');

if(style==0)
  mesh(X, Y, z);  
  view([0 90]);
  colorbar;
else
  surf(X,Y,z,'FaceColor','interp','EdgeColor','none','FaceLighting','phong');
  axis tight;
  camlight left;
  view([0 90]);
  colorbar;
end

if(export==1)
  X = getframe(gcf);
  if isempty(X.colormap)
    imwrite(X.cdata, [exportname '.tif']);
  else
    imwrite(X.cdata, X.colormap, [exportname '.tif']);
  end
  close
end

  
  
