我的数据集如下(例如):
strength = [-90 -90 -90 -90 -40 -20 -22.4 -45 -35 -41 -44 -55 -40 -75 -26]
X = [10 550 550 10 50 234 393 129 237 328 448 225 344 457 477]
Y = [10 10 410 410 293 210 202 132 130 142 141 272 268 274 200]
此处,strength
是接收信号强度,以dBm为单位,X和Y是二维坐标。我想在所有坐标点上绘制信号强度的热图。
我的情况类似于this问题。但是,我想在Matlab中绘制接收到的信号强度,如图所示(由于图像质量)。在Matlab中找到了一个解决方案here,但是,链接中给出的代码不起作用。 Matlab的命令窗口显示具有0行0列的HeatMap对象。 Matlab中的可用代码如下:
strength = [-90 -90 -90 -90 -40 -20 -22.4 -45 -35 -41 -44 -55 -40 -75 -26]';
X = [10 550 550 10 50 234 393 129 237 328 448 225 344 457 477]';
Y = [10 10 410 410 293 210 202 132 130 142 141 272 268 274 200]';
strengthPercent = 2*(strength+100)/100;
picture = imread('https://www.mathworks.com/help/examples/thingspeak/win64/CreateHeatmapOverlayImageTSExample_02.png');
[height,width,depth] = size(picture);
OverlayImage=[];
F = scatteredInterpolant(Y, X, strengthPercent,'linear');
for i = 1:height-1
for j = 1:width-1
OverlayImage(i,j) = F(i,j);
end
end
alpha = (~isnan(OverlayImage))*0.6;
imshow(picture);
hold on
OverlayImage = imshow( OverlayImage );
caxis auto
colormap( OverlayImage.Parent, jet );
colorbar( OverlayImage.Parent );
set( OverlayImage, 'AlphaData', alpha );
请提出任何建议!
谢谢。
您可以按照显示的代码使用scatteredInterpolant
,只需将其与surf
配对
F = scatteredInterpolant(X(:), Y(:), strength(:));
[XD, Yd] = meshgrid( 0:10:410, 0:10:550 );
Zd = F( XD, Yd );
surf( XD, Yd, Zd );
view([90,-90]); % view 3D plot from above
您可以更改colormap
以自定义外观。