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

10 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 May 2013
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.

More Answers (0)

Products


Release

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!