-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataDensity.m
37 lines (34 loc) · 1.16 KB
/
dataDensity.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [ dmap ] = dataDensity( x, y, width, height, limits, fudge )
%DATADENSITY Get a data density image of data
% x, y - two vectors of equal length giving scatterplot x, y co-ords
% width, height - dimensions of the data density plot, in pixels
% limits - [xmin xmax ymin ymax] - defaults to data max/min
% fudge - the amount of smear, defaults to size of pixel diagonal
%
% By Malcolm McLean
%
if(nargin == 4)
limits(1) = min(x);
limits(2) = max(x);
limits(3) = min(y);
limits(4) = max(y);
end
deltax = (limits(2) - limits(1)) / width;
deltay = (limits(4) - limits(3)) / height;
if(nargin < 6)
fudge = sqrt(deltax^2 + deltay^2);
end
dmap = zeros(height, width);
for ii = 0: height - 1
yi = limits(3) + ii * deltay + deltay/2;
for jj = 0 : width - 1
xi = limits(1) + jj * deltax + deltax/2;
dd = 0;
for kk = 1: length(x)
dist2 = (x(kk) - xi)^2 + (y(kk) - yi)^2;
dd = dd + 1 / ( dist2 + fudge);
end
dmap(ii+1,jj+1) = dd;
end
end
end