www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/ExcludeNegativeDataValuesFromColormapExample.m
%% Change Mapping of Data Values into Colormap % This example shows how to control the mapping of data values to colors in % the colormap so that negative data values map to black. % Copyright 2015 The MathWorks, Inc. %% % Create |X|, |Y|, and |Z| as 30-by-30 arrays from the |peaks| function. % Use the arrays to plot a surface. Use |Z| for both the surface height and % the color data. Add a colorbar that shows how the color data values map % to colors in the colormap. [X,Y,Z] = peaks(30); surf(X,Y,Z) colorbar %% % Return the current color limits of the axes, |cmin| and |cmax|. Color % data values less than or equal to |cmin| map to the first color in the % colormap. Values greater than or equal to |cmax| map to the last color in % the colormap. [cmin,cmax] = caxis %% % Change the color limits using |caxis| again. Set the minimum color limit % to |0| so that values of |0| or less map to the first color in the % colormap. Keep the same maximum color limit. caxis([0,cmax]) %% % Return the current colormap as |map|. Set the first color in the colormap % to black by setting the first row of |map| to |[0 0 0]|. Apply the % updated colormap to the figure. map = colormap; map(1,:) = [0 0 0]; colormap(map) %% % All data values less than or equal to |0| map to black.