MATLAB: Using colorbar with imagesc

cmaxcmincolorbarimagesc

I have imported a 500 x 500 text file and have plotted the data using imagesc. I need all the cells in the text file containing a zero to be plotted white, but colour the rest of the data ie start the colorbar from 1 and include all the data up to the maximum number, but making everything that is a zero, white.

Best Answer

Do you need white to actually appear on the colourbar? Doing this can be difficult because colorbars are usually e.g. 256 or 512 values so unless you have only that many data values you will always get multiple values falling in each colour bin since the minimum you could have is a single white colour bin covering e.g. 1/256th of your data.
You can manipulate your data to make this easier, but if you don't need the white to be on the colourmap, then I would just use AlphaData to make the 0 data transparent. If you need to you could create a white patch of the size of the axes under your image, but the axes themselves are white by default so you shouldn't need to do this.