cname=colorname(cs,[num])
cs : | color such such as 'r--', or {'r--','b.-'} | |
num : | length of format; 0 is automatic |
cname : | string or cell list of strings |
colorname({'b--','y'},3)
This function, colorname
, is designed to return a name for a color string or a list of color strings. It is part of the SolidGeometry library and was introduced in version 5.1. The function takes two input parameters and returns a string or a cell list of strings as output.
The function begins by determining the value of num
using the helper function getfuncparams
. It then defines a lookup table, tab
, which maps single-character color codes to their corresponding color names.
If cs
is a scalar and numeric, it is converted to a color string using the colofn
function.
If cs
is a cell array, the function iterates over each element, recursively calling colorname
for each color string. The results are stored in a cell array cname
. The function then converts this cell array to a string using cell2str
and updates cname
with these string values.
If cs
is not a cell array, the function checks if the first character of cs
matches any entry in the first column of tab
. If a match is found, cname
is set to the corresponding color name from the second column of tab
.
If num
is specified and greater than 0, the function formats cname
to the specified length using sprintf
.
If no match is found in tab
, cname
is set to an empty array.
Calling colorname({'b--','y'},3)
will return a cell array with formatted color names for the input color strings.