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

3 次查看(过去 30 天)
For example, if any location is within 10m of the sensor node, it should be coloured in red and if a location is far away from any node it should be coloured in blue. how can i generate such a heatmap

采纳的回答

Don Mathis
Don Mathis 2019-1-4
编辑:Don Mathis 2019-1-4
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');
  5 个评论
Suniti
Suniti 2019-1-9
22.jpg
as in the picture above, the area covered by sensor nodes is one solid color and we cannot visually see the exact location of sensor nodes as opposed to the following figure
Figure 2.jpg
where boundaries are visible for all sensor locations

请先登录,再进行评论。

更多回答(2 个)

KSSV
KSSV 2018-12-18
Read about pcolor, surf, imagec
  3 个评论
Suniti
Suniti 2019-1-3
I have 100 sensor nodes placed in a 100*100 square metres square field. Each sensor node has a sensing radius of 5 metres as shown in the figure (where small blue circles and magenta diamonds are the sensors and the dotted blue and magenta circles show their sensing ranges). I want to plot a heatmap that shows the areas that are not covered by sensing ranges of any sensors. The areas which are covered by sensors are to be depicted in shades of red and the areas which are far away from the sensing ranges are depicted in shades of blue (The sensing power keeps on decreasing as distance from centre of sensor keeps on increasing with full sensing at centre and zero at the edge of sensing circle)12.jpg
Now what I have done uptil now for my code is this:
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);
imagesc(xxx, yyy, reshape (D, size(XXX)));
set(gca, 'XLim', xxx([1 end]), 'YLim', yyy([1 end]), 'YDir', 'normal');
colormap(flip(jet(), 1))
In the above code, xcord and ycord are 100*1 matrices containing x and y coordinates of 100 sensor nodes respectively. xcordt and ycordt are their transpose forms.
This gives me a figure like this at the start of my network when there all all 100 nodes:
13.jpg
However, when certain sensors are drained of their energy and they die out, I again plot the graph with fewer sensors (30 sensors now) and the graph comes out to be like this:
14.jpg
Now in this graph, visually the number of sensors are 30, but the colormap has increased in size giving the wrong impression that the sensing range of sensors has increased. This may be happening because in my code I have been using smallest euclidean distance as a measure to plot the graph.
What I actually want is that the plot should be a heatmap of points (sensor locations) and their sensing ranges (in circular form) should be continuously coloured from red and centre towards blue at edges and also all the non-covered aeas (non-coveredby sensing ranges of sensors) should be blue as in the figure below:
at start of network:
21.jpg
after few nodes die:
22.jpg
after few more nodes die:
23.jpg
Now in all the above three figures, visually everything is correct and the sensing ranges of all sensors are same. I dont know what am I doing wrong. Please help.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2018-12-18
  4 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mapping 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by