# I have 100 sensor nodes placed at coordinates (x and y) inside a 100*100 m2square field. I want to plot a heatmap showing proximity of all other locations to these sensor nodes

5 views (last 30 days)

Show older comments

##### 0 Comments

### Accepted Answer

Don Mathis
on 4 Jan 2019

Edited: Don Mathis
on 4 Jan 2019

Is this closer to what you want?

%% 100 points

rng(0)

xcord = rand(100,1)*100;

ycord = rand(100,1)*100;

xcordt = xcord';

ycordt = ycord';

radius = 5;

figure

new=[xcord ycord];

xxx=linspace(min(new(:,1)),max(new(:,1)),100);

yyy=linspace(min(new(:,2)),max(new(:,2)),100);

[XXX, YYY] = meshgrid(xxx,yyy);

D = pdist2([xcordt(:) ycordt(:)], [XXX(:) YYY(:)], 'euclidean', 'Smallest', 1);

sz = size(XXX);

reds = double(D<=radius) .* (1-D/radius);

blues = double(D>radius) .* ((D-radius)/max(D-radius));

Color = zeros([sz 3]);

Color(:,:,1) = reshape(reds, sz);

Color(:,:,3) = reshape(blues, sz);

image(xxx, yyy, Color);

set(gca, 'XLim', xxx([1 end]), 'YLim', yyy([1 end]), 'YDir', 'normal');

%% first 30 points

rng(0)

xcord = rand(100,1)*100;

ycord = rand(100,1)*100;

radius = 5;

figure

xcord = xcord(1:30);

ycord = ycord(1:30);

xcordt = xcord';

ycordt = ycord';

new=[xcord ycord];

xxx=linspace(min(new(:,1)),max(new(:,1)),100);

yyy=linspace(min(new(:,2)),max(new(:,2)),100);

[XXX, YYY] = meshgrid(xxx,yyy);

D = pdist2([xcordt(:) ycordt(:)], [XXX(:) YYY(:)], 'euclidean', 'Smallest', 1);

sz = size(XXX);

reds = double(D<=radius) .* (1-D/radius);

blues = double(D>radius) .* ((D-radius)/max(D-radius));

Color = zeros([sz 3]);

Color(:,:,1) = reshape(reds, sz);

Color(:,:,3) = reshape(blues, sz);

image(xxx, yyy, Color);

set(gca, 'XLim', xxx([1 end]), 'YLim', yyy([1 end]), 'YDir', 'normal');

### More Answers (2)

Walter Roberson
on 18 Dec 2018

##### 4 Comments

Walter Roberson
on 9 Jan 2019

Use a higher subpixels value until you are satisfied with the smoothness.

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!