MATLAB: Does the colorbar in the figure reposition itself when I print the figure in MATLAB 7.0.1 (R14SP1)

colorbarMATLABposition;printrepositionresizeunits

If I create a colorbar and then reposition it as in the following example, the colorbar will return to its original postion when I print or resize the figure.
surf(peaks)
hcb = colorbar;
set(hcb,'units','centimeter','position',[8 1 2 3])

Best Answer

This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
We have verified that there is a bug in MATLAB 7.0.1 (R14) in the way that it resizes figures containing a colorbar whose 'Units' property is not set to 'normalized'.
To work around this issue, use normalized units when creating the colorbar. For instance, replace the example above with the following:
hf = figure('units','centimeters');
surf(peaks)
% Convert centimeters to normalized units
figPosCM = get(hf,'Position');
posNormalized = [8./figPosCM(3) 1./figPosCM(4) 2./figPosCM(3) 3./figPosCM(4)];
% Create colorbar in a nondefault location using normalized units
hcb = colorbar('units', 'normalized','position',posNormalized);