You can hide zero values in a bar3 plot, but that solution is not directly applicable to hist3()
even though the workaround is similar in fashion.
Here's a workaround based on imdilate()
which requires the Image Processing TB and I would like to see suggestions that are Toolbox independent (only Stats TB is ok).
% Example graph
hist3([2 0; 0 1; 1 1],[2 2])
% handle to graph3d.surfaceplot
h = get(gca,'child');
% retrieve the heights
heights = get(h,'Zdata');
% Index outer heights leaving a contour of zeros
mask = ~logical(imdilate(heights,ones(3)));
% Set the zero heights to NaN
heights(mask) = NaN;
% Final result
set(h,'ZData',heights)
Here's what happens to heights
:
heights =...
[0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 1 1 0 0
0 1 1 0 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0]
mask =...
[1 1 1 1 1 0 0 0 0 1
1 1 1 1 1 0 0 0 0 1
1 1 1 1 1 0 0 0 0 1
1 1 1 1 1 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
0 0 0 0 1 0 0 0 0 1
0 0 0 0 1 0 0 0 0 1
0 0 0 0 1 0 0 0 0 1
0 0 0 0 1 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1]
heights =...
[NaN NaN NaN NaN NaN 0 0 0 0 NaN
NaN NaN NaN NaN NaN 0 1 1 0 NaN
NaN NaN NaN NaN NaN 0 1 1 0 NaN
NaN NaN NaN NaN NaN 0 0 0 0 NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
0 0 0 0 NaN 0 0 0 0 NaN
0 1 1 0 NaN 0 1 1 0 NaN
0 1 1 0 NaN 0 1 1 0 NaN
0 0 0 0 NaN 0 0 0 0 NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN]