How to plot heatmap using x y and z data

26 vues (au cours des 30 derniers jours)
Kabit Kishore
Kabit Kishore le 19 Fév 2022
Hi i am trying to create a heat map using x, y, and z data where x , y is the coordinates and z is the measured value. I have tried using heatmap command however i am not getting my desired outcome. Any help is appreciated. Thank you
tbl = table(x,y,z)
h = heatmap(tbl,'x','y','ColorVariable','z')

Réponse acceptée

Simon Chan
Simon Chan le 20 Fév 2022
You may refer to the following example to make sure your variable x,y and z are in similar format.
xcoord = 1.5:0.1:3; % x-coordinates from 1.5 to 3.0
ycoord = 2:0.1:5; % y-coordinates from 2.0 to 5.0
[X,Y] = meshgrid(xcoord,ycoord);
zdata = randi([5 30], numel(xcoord),numel(ycoord)); % Simulate the data
x = X(:); % Your varaible x should something like this as a column vector
y = Y(:); % Similar for variable y
z = zdata(:); % Similar for variable z
tbl = table(x,y,z); % Combine them in a table
h = heatmap(tbl,'x','y','ColorVariable','z'); % Generate heat map

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by