MATLAB Answers


How to set background as black without appearing in colorbar?

Asked by Shing
on 29 Mar 2013

Hi, I have an image and the pixel values range from 0 to 180, represented by jet colorbar range.

However, I would like to differentiate my object in the image with its background by setting the background pixels out of the [0 180] range, such as 500, and make the pixels which have 500 value to be black.

But I do not want it to appear as part of the color bar. How can I go about doing that ??

Any form of help is much appreciated and happy holiday! :)


Log in to comment.


No products are associated with this question.

2 Answers

Answer by Doug Hull on 29 Mar 2013

Axes have color. You could set the color of the axes. Then you can put NaN in the image on any pixel you want to be 'empty'.

  1 Comment


I tried setting NaN into my image matrice. But how do I go about setting it as black background without it appearing within color bar?

Log in to comment.

Answer by Sean de Wolski
on 29 Mar 2013

Set the 'YLim' property of the colorbar to be the range you want:

h = colorbar;
set(h,'YLim',[2 5]);


Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!