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

1 回表示 (過去 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 件のコメント
Suniti
Suniti 2019 年 1 月 9 日
i am still not getting smooth circles by this, Sir.
Walter Roberson
Walter Roberson 2019 年 1 月 9 日
Use a higher subpixels value until you are satisfied with the smoothness.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMapping についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by