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
댓글 수: 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!