MATLAB - Redefine YTickLabel

I have a problem with editing the colorbar in MATLAB. The colorbar is drawn and I want to add the unit (dB) for the specific measurement on YTickLabels. This is done by following commands:

cy = get(ch,'YTickLabel');  
set(ch,'YTickLabel',strcat(cy,{' dB'})); 

But when I resize the figure, MATLAB redefines the intervals, and the output is repeated twice, like:

10 dB, 20 dB, 30 dB, 10 dB, 20 dB, 30 dB instead of 10 dB, 20 dB, 30 dB.

How do I prevent MATLAB from redefining its Y axis ticks, so it doesn't mess up my colorbar?


In order to keep the y-axis tick values from being changed when the figure is resized, you will have to either explicitly set the 'YTick' property or set the 'YTickMode' property to 'manual' (to keep it from being automatically changed). You may also have to explicitly set the 'YLim' property as well (or set the 'YLimMode' property to 'manual') to keep the limits of the color bar from changing. Here's one possible solution:

labels = get(ch,'YTickLabel');    %# Get the current labels
set(ch,'YLimMode','manual',...    %# Freeze the current limits
       'YTickMode','manual',...   %# Freeze the current tick values
       'YTickLabel',strcat(labels,{' dB'}));  %# Change the labels

You can also define the tick properties when you create the color bar in your initial call to the COLORBAR function. For example, if you know you will want to have 3 tick values at 10, 20, and 30 with "dB" added to the labels, you can create the color bar in the following way:

ch = colorbar('YLim',[10 30],...                        &# The axis limits
              'YTick',[10 20 30],...                    %# The tick locations
              'YTickLabel',{'10 dB','20 dB','30 dB'});  %# The tick labels

These limits, tick values, and tick labels should also remain unchanged when the figure is resized.

You have to set manually YTick property as well, so it will not change with figure resize.

cytick = get(ch,'YTick');    

Need Your Help

iPhone Core Data :: basic design for view preference objects of underlying data

iphone objective-c ios core-data modeling

I am using Core Data, and have created the following objects in my xcdatamodel:

NHibernate Caching Dilemma

nhibernate caching rdbms second-level-cache

My application includes a client, web tier (load balanced), application tier (load balanced), and database tier. The web tier exposes services to clients, and forwards calls onto the application ti...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.