MATLAB: How to change the color of zero or nan Zdata in BAR3 plot

bar3colormap

I have 3D bar graph where length of the YData is not always the same so I have several zero Zdata values. I would like to set zero Zdata to white color. I changed zero Zdata to nan but bar3 function still gives the color of the bar graph even for the nan or zeros. Any help would be appreciated. Thank you.
Sandra

Best Answer

You will have to set the surface's 'cdata' and 'zdata' to nan.
For example:
x = magic(4);
bar3(x)
h = get(gca,'children'); %surfaces making up each bar group
h4c = get(h(4),'cdata');
set(h(4),'cdata',[nan(6,4);h4c(7:end,:)]) %6 rows per bar
h4z = get(h(4),'zdata');
set(h(4),'zdata',[nan(6,4);h4c(7:end,:)]);