필터 지우기
필터 지우기

Making a heat map from three vectors of different lengths

조회 수: 13 (최근 30일)
ct8
ct8 2022년 11월 14일
편집: ct8 2024년 4월 17일
From a set of three vectors (x,y,z), I want to generate a heat map of x,y and z where the color bar would denote z-values.Perhaps this answer was relevant https://www.mathworks.com/matlabcentral/answers/105390-making-a-heat-map-from-three-vectorsBut it was erased from the database. Thanks!
  댓글 수: 1
Adam Danz
Adam Danz 2022년 11월 14일
That answer was added in 2013 but matlab's heatmap came out in 2017. However, the bioinformatics Toolbox has a function HeatMap that has been available since 2009. My answer shows how to use the newer heatmap function. Note that you could also use imagesc to create a similar plot.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2022년 11월 14일
편집: Adam Danz 2022년 11월 14일
In heatmap, XData define the number of columns and YData define the number of rows. Your matrix y is 21x10 meaning there will be 21 rows and 10 columns.
load('matlab.mat');
heatmap(z,x,y)
If you want there to be 10 rows and 21 columns,
figure
heatmap(x,z,y'); % note the transpose on y
How to remove cell labels
The examples above do not show the cell labels because the axes are too small given the number of cells but to remove the cell labels,
h = heatmap(__)
h.CellLabelColor = 'none';
Alternative: imagesc
Another option is to use imagesc but note
  • The direction of the y-axis differs between heatmap and imagesc
  • imagesc sorts the x and y values
Yet another alternative is to use histogram2.
figure()
imagesc(z,x,y)
% reproduce heatmap's colormap
n=256;
cmap = [linspace(.9,0,n)', linspace(.9447,.447,n)', linspace(.9741,.741,n)'];
colormap(cmap);
axis xy
colorbar()
  댓글 수: 3
Adam Danz
Adam Danz 2022년 11월 14일
See updated answer.
ct8
ct8 2022년 11월 14일
Neat! Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by