MATLAB: How to make a figure similar to the one produced by the SURFC function, but with a histogram

hist3dMATLABpcolorprojectedview

I would like to make a figure similar to the one produced by the SURFC function, but with a histogram.

Best Answer

In order to create a figure similar to SURFC but with a 3D histogram, the PCOLOR function can be used.
Given a data set (where the first column of data represents width
and second column represents height in meters), to draw a 3-D histogram using HIST3. use the PCOLOR function to create a 2-D map of the values projected to the base plane as follows:
% Data
dat=[70 71 71 60 55 45 40 40 ;1.8 1.8 1.5 1.5 1.6 1.2 1.3 1.3]';
hold on
hist3(dat)
title('Hist3D');
n = hist3(dat);
n1 = n';
n1( size(n,1) + 1 ,size(n,2) + 1 ) = 0;
% Bottom projected view
y = linspace( min(dat(:,2)) , max(dat(:,2)) , size(n,1) + 1);
x = linspace( min(dat(:,1)) , max(dat(:,1)) , size(n,1) + 1);
h = pcolor(x,y,n1)
set(h, 'zdata', ones(size(n1)) * -1) % projection view offset
colormap(hot) % heat map
title(sprintf('Hist3D with Heat Map Projected View'));
grid on
view(3);