MATLAB: How to prevent bar3 shading the sides of the bars

shading bar3

Hi there,
I have never used MATLAB bar charts before and I am trying to show four-dimensional data, such that the height of the bars refers to the frequency of an x,y combination and the color refers to another dataset.
I am using this code which I found as an answer to a different question.
A = rand(10,10);
A2 = rand(10,10);
figure(1)
b1= bar3(A);
figure(2)
b = bar3(A2);
hcb = colorbar;
for k = 1:length(b)
b(k).CData = b1(k).ZData;
b(k).FaceColor = 'flat';
end
The code was originally written using FaceColor 'interp' but I would like one color per bar. As you can see, when I use 'flat', I get the colors I want, but shading on the sides of the bars which I really don't want.
Any ideas on how to get rid of this would be appreciated!

Best Answer

OK, I did figure out how to modify the .ZData values written to get the proper effect.
...
for k = 1:length(b)
zd=b1(k).ZData; % retrieve the ZData to write as CData
ix=isfinite(zd(:,1)); % the faces with color values locations
zd(ix,1)=zd(ix,2); % use same color for first coordinate, too
b(k).CData = zd;
b(k).FaceColor = 'flat';
end
Used subplot() to shrink images down but above mod yields
The key to how/why this works is shown in the documentation for surface properties under 'FaceColor' in how the 'CData' value is interpreted. NB: for 'flat' the LLH corner location is used for the associated face and the default value for that location in the 4-vector in bar3 is 0 for the base color of the scaled range, but the second/third vertices are set to the scaled values. The above simply replaces that zero with the scaled value for the second and thus the face to the left is now also the same color.
Somewhere in there is undoubtedly a flag/property that could be tweaked to generate the CData values to not shade the one face but I couldn't find it; it came to me overnight I had done something like this quite some time ago but I had to reinvent it as had forgotten just what/how.