MATLAB: Is it possible to allow Colorbar to have Units in MATLAB 8.1 (R2013a)

colorbarlabel;MATLABunits

Allow Colorbar to have Units. Add unit for Colorbar scale.
Right now, only numbers are shown on the colorbar, frequency unit such as meter [m], second [s] would be very helpful.

Best Answer

The ability to allow Colorbar to have units is not available in MATLAB 8.1 (R2013a).
To work around this issue, you can directly modify the labels of the colorbar. To do this you will need the handle to the colorbar, so you need to initially create the colorbar using the following command:
h = colorbar;
Once you have the handle saved in the variable h, you can determine the current Y-axis labels using:
ylabel = get(h,'YTickLabel');
the variable 'ylabel' now contains a character array with each row representing one label. You can modify this array to add units and then set the new array to be the colorbar labels using:
set(h,'YTickLabel',ylabel);
For example the following lines of code will add a colorbar and then will add 'mm' units to the tick labels:
h = colorbar;
ylabel = get(h,'YTickLabel');
mm = repmat(' mm',size(ylabel,1),1);
ylabel = [ylabel mm];
set(h,'YTickLabel',ylabel);
NOTE: This workaround may not work when the limits of the colorbar have exponents, such as 1E5, as the exponent part will be removed.