MATLAB: Display colorbar label horizontally and specify its position

figureplot

In this example
figure;
[x, y, z] = sphere;
surf(x, y, z);
c = colorbar;
c.Label.String = 'Z';
I would like the colorbar label to be displayed vertically and in the top right corner off the colorbar. How can I do it?

Best Answer

EDITED
pos = get(c,'Position');
c.Label.Position = [pos(1)/2 pos(2)+1]; % to change its position
c.Label.Rotation = 0; % to rotate the text