MATLAB: Change the background of image plotted using imagesec

image analysis

Hi! I am plotting a data matrix using the following code:
imagesc(x,y,Data)
colorbar
set(colorbar, 'ylim', [1 10])
The "Data" matrix has a lot of "0"s among 480×480 elements. Rest members of the matrix are from 1 to 9. My plot is looking quite blue because of the of the 0's. How can I set the threshold so that there will be no color for the 0's but only the colors will starts to show up for non-zero values of the "Data" matrix elements?

Best Answer

Note that every time you call colorbar you create a new colorbar that replaces the previous one:
colorbar %this creates a colorbar
set(colorbar, 'ylim', [1 10]) %this creates a new colorbar and replace the previous one with it.
You cannot have no color. If you want the zero values to have the same colour as the figure background:
imagesc(x,y,Data);
set(colorbar, 'ylim', [1 10]) %creates colour bar and set its limit all at once
cmap = colormap;
cmap(1, :) = get(gcf, 'Color'); %replace first colour (used for 0) by figure colour
colormap(cmap);