필터 지우기
필터 지우기

Why does histogram data from hist3 have to be transposed?

조회 수: 2 (최근 30일)
lalikesbrains
lalikesbrains 2016년 8월 25일
댓글: lalikesbrains 2016년 8월 26일
I just learnt how to use hist3 and I don't understand a couple of lines in the example code that Matlab help provided. I've copy pasted the example for plotting a density histogram with intensity map (an intensity map is what I'm interested in plotting actually). The two lines that I don't understand are: 1. n1 = n'; --> why does the histogram have to be transposed? 2. h.ZData = ones(size(n1)) * -max(max(n)); --> what does this line do?
%Load the sample data.
load seamount
%Correct grid for negative y-values and draw histogram in 2D.
hold on
dat = [-y,x];
hist3(dat)
%Extract histogram data.
n = hist3(dat); % default is to 10x10 bins
n1 = n';
n1(size(n,1) + 1, size(n,2) + 1) = 0;
%Generate grid for 2-D projected view of intensities.
xb = linspace(min(dat(:,1)),max(dat(:,1)),size(n,1)+1);
yb = linspace(min(dat(:,2)),max(dat(:,2)),size(n,1)+1);
%Make a pseudocolor plot.
h = pcolor(xb,yb,n1);
h.ZData = ones(size(n1)) * -max(max(n));
colormap(hot) % heat map
title('Seamount:Data Point Density Histogram and Intensity Map');
grid on
view(3);

채택된 답변

Thorsten
Thorsten 2016년 8월 26일
편집: Thorsten 2016년 8월 26일
1. 1. n1 = n'; --> why does the histogram have to be transposed?
Because dat is defined as
dat = [-y, x]
but the grid is defined with xb from the first column (that is -y) and yb from the second column of dat, which is x:
xb = linspace(min(dat(:,1)),max(dat(:,1)),size(n,1)+1);
yb = linspace(min(dat(:,2)),max(dat(:,2)),size(n,1)+1);
To get the right mapping for the x and y axis in the plot
h = pcolor(xb,yb,n1);
the n1 has to be transposed before.
2. h.ZData = ones(size(n1)) * -max(max(n)); --> what does this line do?
This moves the pcolor plot down by max(max(n) to appear below the hist3 plot.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by