iscolor.m

来自「有关matlab的电子书籍有一定的帮助希望有用」· M 代码 · 共 28 行

M
28
字号
function bool = iscolor(c)
%ISCOLOR  True if input is a color.
%   ISCOLOR(C) is 1 if c is a valid colorspec and 0 else.
%   Valid colorspecs are: 'r','g','b','w',... (a single character).
%                         [r g b] where r,g and b are scalars in [0,1]
%                         n-by-3 matrix with elements in the range [0,1]

%   Copyright (c) 1988-98 by The MathWorks, Inc.
% $Revision: 1.4 $

% Author: T. Krauss

if isstr(c)
    colorStr = {'y' 'm' 'c' 'r' 'g' 'b' 'w' 'k'};  % see 'help plot'
    bool = ~isempty(findcstr(colorStr,c));
else
    if any(abs(imag(c))>0.0)
        bool = 0;
    elseif min(size(c))>1
        if size(c,2)~=3
            bool = 0;
        else
            bool = max(max(c))<=1.0 & min(min(c))>=0.0;
        end
    else
        bool = max(max(c))<=1.0 & min(min(c))>=0.0;
    end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?