How to plot heatmap using x y and z data
32 views (last 30 days)
Show older comments
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')

0 Comments
Accepted Answer
Simon Chan
on 20 Feb 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
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!