如何将颜色名称转换为3元素RGB向量? [英] How can I convert a color name to a 3 element RGB vector?

查看:901
本文介绍了如何将颜色名称转换为3元素RGB向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多MATLAB绘图函数中,您可以将颜色指定为字符串或直接列出红色,绿色和蓝色值的3元素向量.

In many MATLAB plotting functions, you can specify the color as either a string or as a 3 element vector that directly lists the red, green, and blue values.

例如,这两个语句是等效的:

For instance, these two statements are equivalent:

plot(x, y, 'Color', 'r');
plot(x, y, 'Color', [1 0 0]);

可以通过字符串值'r','g','b','c','m','y','k','w'指定8种颜色.是否有MATLAB内置函数将这些字符串转换为等效的RGB向量?

There are 8 colors that can be specified by a string value: 'r','g','b','c','m','y','k','w'. Is there a MATLAB built-in function that converts these strings to an equivalent RGB vector?

推荐答案

我在 MathWorks File Exchange 甚至可以处理除MATLAB中的默认8以外的颜色字符串:

I found this general alternative on the MathWorks File Exchange which will even handle color strings other than the default 8 in MATLAB:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆