Convert ColorSpec string to RGB triplet - MATLAB Cody - MATLAB Central

Problem 42612. Convert ColorSpec string to RGB triplet

Difficulty:Rate

Given a ColorSpec string, either in short or long form, return the corresponding RGB triplet. If the input is not a valid color, return an empty vector.

Examples

str2rgb('red') returns [1 0 0]
str2rgb('k') returns [0 0 0]
str2rgb('pizza') returns []

Solution Stats

43.94% Correct | 56.06% Incorrect
Last Solution submitted on Feb 27, 2025

Problem Comments

Solution Comments

Show comments
Who Deserves Your Praise? Discover the New Contribution Widget!
...
We are excited to announce another update to our Discussions area: the...

Problem Recent Solvers51

Suggested Problems

More from this Author44

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page