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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (2 件)
Walter Roberson
2018 年 12 月 18 日
4 件のコメント
Walter Roberson
2019 年 1 月 9 日
Use a higher subpixels value until you are satisfied with the smoothness.
参考
カテゴリ
Help Center および File Exchange で Mapping についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!