% CC: 2009, Raazesh Sainudiin and Carl Scarrott
% CCL Attribution-Noncommercial-Share Alike 3.0 New Zealand License
%
% data set captured by pausing the map scene and tracing points on
% transparenc; then ovelayed on graphing paper to get co-ordinates
data=[3.2,19.6; 4.4,18.7; 4,17.8;  1.9,17.1; 2.1,13.4;9.3,18.4; 4.2,10.9; 6.9,12.8; 8.4,13.9; 7.3,11.6; 3.8,8.3]

% MATLAB's mesh grid data structure
[X,Y]=meshgrid(linspace(-10,20,100),linspace(-10,40,100));

% convenieent 1-D columns of meshgrid
XS=X(:);
YS=Y(:);

% find sum of (squared) distances to data points
sumdists=zeros(length(XS),1); % allocate memory

% two loops
for i=1:length(XS)
    for j=1:length(data)
        %Sum of distances to data paints
        sumdists(i)=sumdists(i)+sqrt((XS(i)-data(j,1))^2+(YS(i)-data(j,2))^2);
        %Sum of Squared distances to data paints
        %sumdists(i)=sumdists(i)+(XS(i)-data(j,1))^2+(YS(i)-data(j,2))^2;
    end
end
Z=nan*zeros(size(X)); % allocate memory
Z(find(isnan(Z)))=1./sumdists; % invert for heat map

% plot
figure(1);clf;imagesc(Y(:,1),X(1,:),Z');colorbar;hold on;plot(data(:,2),data(:,1),'k*')
