How to plot heatmap using x y and z data

32 ビュー (過去 30 日間)
Kabit Kishore
Kabit Kishore 2022 年 2 月 19 日
回答済み: Simon Chan 2022 年 2 月 20 日
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')

採用された回答

Simon Chan
Simon Chan 2022 年 2 月 20 日
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 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by