MATLAB - Override YTickLabel

I have a problem editing a colorbar in MATLAB. The color bar is drawn, and I want to add a block (dB) for a specific measurement on YTickLabels. This is done using the following commands:

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

But when I resize the shape, MATLAB redefines the intervals, and the result is repeated twice, for example:

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 overriding its Y-axis ticks so that it does not ruin my color bar?

+5
source share
2 answers

y , 'YTick' 'YTickMode' 'manual' ( ). , 'YLim' ( 'YLimMode' 'manual'), . :

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

COLORBAR. , , 3 10, 20 30 "" , :

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

, .

+5

YTick , .

cytick = get(ch,'YTick');    
set(ch,'YTick',cytick);
0

All Articles