1

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])

enter image description here

% 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)

enter image description here

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]
4

1 回答 1

3

您可以替换imdilate(height, ones(3))

filter2(ones(3), height)

或者

conv2(ones(3), height, 'same') 

也不需要工具箱。

于 2013-07-04T18:19:03.347 回答