time | calls | line |
---|
| | 1 | function map = colormap(arg1,arg2)
|
| | 2 | %COLORMAP Color look-up table.
|
| | 3 | % COLORMAP(MAP) sets the current figure's colormap to MAP.
|
| | 4 | % COLORMAP('default') sets the current figure's colormap to
|
| | 5 | % the root's default, whose setting is PARULA.
|
| | 6 | % MAP = COLORMAP returns the three-column matrix of RGB triplets defining
|
| | 7 | % the colormap for the current figure.
|
| | 8 | % COLORMAP(FIG,...) sets the colormap for the figure specified by FIG.
|
| | 9 | % COLORMAP(AX,...) sets the colormap for the axes specified by AX.
|
| | 10 | % Each axes within a figure can have a unique colormap. After you set
|
| | 11 | % an axes colormap, changing the figure colormap does not affect the axes.
|
| | 12 | % MAP = COLORMAP(FIG) returns the colormap for the figure specified by FIG.
|
| | 13 | % MAP = COLORMAP(AX) returns the colormap for the axes specified by AX.
|
| | 14 | %
|
| | 15 | % A color map matrix may have any number of rows, but it must have
|
| | 16 | % exactly 3 columns. Each row is interpreted as a color, with the
|
| | 17 | % first element specifying the intensity of red light, the second
|
| | 18 | % green, and the third blue. Color intensity can be specified on the
|
| | 19 | % interval 0.0 to 1.0.
|
| | 20 | % For example, [0 0 0] is black, [1 1 1] is white,
|
| | 21 | % [1 0 0] is pure red, [.5 .5 .5] is gray, and
|
| | 22 | % [127/255 1 212/255] is aquamarine.
|
| | 23 | %
|
| | 24 | % Graphics objects that use pseudocolor -- SURFACE and PATCH objects,
|
| | 25 | % which are created by the functions MESH, SURF, and PCOLOR -- map
|
| | 26 | % a color matrix, C, whose values are in the range [Cmin, Cmax],
|
| | 27 | % to an array of indices, k, in the range [1, m].
|
| | 28 | % The values of Cmin and Cmax are either min(min(C)) and max(max(C)),
|
| | 29 | % or are specified by CAXIS. The mapping is linear, with Cmin
|
| | 30 | % mapping to index 1 and Cmax mapping to index m. The indices are
|
| | 31 | % then used with the colormap to determine the color associated
|
| | 32 | % with each matrix element. See CAXIS for details.
|
| | 33 | %
|
| | 34 | % Type HELP GRAPH3D to see a number of useful colormaps.
|
| | 35 | %
|
| | 36 | % COLORMAP is a function that sets the Colormap property of a figure.
|
| | 37 | %
|
| | 38 | % See also HSV, CAXIS, SPINMAP, BRIGHTEN, RGBPLOT, FIGURE, COLORMAPEDITOR.
|
| | 39 |
|
| | 40 | % Copyright 1984-2010 The MathWorks, Inc.
|
| | 41 |
|
| 16 | 42 | arg = 0;
|
| 16 | 43 | if (nargin == 0)
|
| | 44 | figH = gcf;
|
| 16 | 45 | elseif (ischar(arg1))||(length(arg1) > 1)||isempty(arg1)
|
| | 46 | % string input (check for valid option later)
|
| 16 | 47 | if (nargin == 2)
|
| | 48 | error(message('MATLAB:colormap:InvalidFirstArgument'));
|
| | 49 | end
|
| 16 | 50 | figH = gcf;
|
| 16 | 51 | if (ischar(arg1))
|
| | 52 | arg = lower(arg1);
|
| 16 | 53 | else
|
| 16 | 54 | arg = arg1;
|
| 16 | 55 | end
|
| | 56 | else
|
| | 57 | % figH can be any object that can contain a colormap
|
| | 58 | figH = getColorMapContainer(arg1);
|
| | 59 | if isempty(figH)
|
| | 60 | error(message('MATLAB:colormap:NeedScalarHandle'));
|
| | 61 | end
|
| | 62 |
|
| | 63 | % check for string option
|
| | 64 | if nargin == 2
|
| | 65 | if (ischar(arg2))
|
| | 66 | arg = lower(arg2);
|
| | 67 | else
|
| | 68 | arg = arg2;
|
| | 69 | end
|
| | 70 | end
|
| | 71 | end
|
| | 72 |
|
| 16 | 73 | if isequal(arg,0)
|
| | 74 | map = get(figH, 'Colormap');
|
| | 75 | return
|
| | 76 | end
|
| 16 | 77 | if ischar(arg)
|
| | 78 | if strcmp(arg,'default')
|
| | 79 | if ~graphicsversion(figH,'handlegraphics')
|
| | 80 | fig = ancestor(figH,'figure');
|
| | 81 | defaultMap = get(fig,'defaultfigureColormap');
|
| | 82 | set(figH,'Colormap',defaultMap);
|
| | 83 | return;
|
| | 84 | else
|
| | 85 | set(figH,'Colormap','default');
|
| | 86 | return;
|
| | 87 | end
|
| | 88 | end
|
| | 89 | k = min(strfind(arg,'('));
|
| | 90 | if ~isempty(k)
|
| | 91 | arg = feval(arg(1:k-1),str2double(arg(k+1:end-1)));
|
| | 92 | else
|
| | 93 | arg = feval(arg);
|
| | 94 | end
|
| | 95 | end
|
| 16 | 96 | if ~isempty(arg)
|
| 16 | 97 | if (size(arg,2) ~= 3)
|
| | 98 | error(message('MATLAB:colormap:InvalidNumberColumns'));
|
| | 99 | end
|
| 16 | 100 | if min(min(arg)) < 0 || max(max(arg)) > 1
|
| | 101 | error(message('MATLAB:colormap:InvalidInputRange'))
|
| | 102 | end
|
| 16 | 103 | end
|
0.01 | 16 | 104 | set(figH, 'Colormap', arg);
|
| 16 | 105 | if nargout == 1
|
| | 106 | map = get(figH, 'Colormap');
|
| | 107 | end
|
| 16 | 108 | end
|
Other subfunctions in this file are not included in this listing.