How to plot heatmap using x y and z data

32 Ansichten (letzte 30 Tage)
Kabit Kishore
Kabit Kishore am 19 Feb. 2022
Beantwortet: Simon Chan am 20 Feb. 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')

Akzeptierte Antwort

Simon Chan
Simon Chan am 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

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by