File Exchange

image thumbnail

name2rgb

version 1.0.0.0 (1.63 KB) by Peder Axensten
Return the rgb vector of a color name.

0 Downloads

Updated 24 Jul 2006

View License

USAGE: color_vector= name2rgb(color_name)

Return the rgb vector of a color name.

EXAMPLE:
name2rgb2({'r', 'blue', 'pp', 'y'})
ans = 1 0 0 0 0 1 NaN NaN NaN 1 1 0

HISTORY:
Version 1.0, 2006-07-19.
Version 1.1, 2006-07-22:
- Much more efficient (and elegant?) code, thanks to Urs (us) Schwarz!

Copyright (C) Peder Axensten <peder@axensten.se>

Comments and Ratings (3)

Jan

All contributions of the FileExchange are published under the BSD license. The automatically attached license file contains a copy right note also. There is nothing wrong with including a copy right note in the code and this does not limit the usage apart from the limits mentioned in the license conditions.

Duane Hanselman

What is the purpose of the copyright? What limitations does your copyright place on use of the code? Are we not allowed to open the file to see what is in it? Are we not allowed to use it? How are you going to monitor and enforce whatever your copyright is? Is it subject to international law?

Get rid of the copyright. It serves NO purpose whatsoever.

urs (us) schwarz

with the exception of the copyright... this code could be slightly optimized as outlined below

% build a template (here just exemplary),
% which is easy to maintain
tmpl={
'r' [1,0,0]
'red' [1,0,0]
'g' [0,1,0]
'b' [0,0,1]
};
% assume the input looks like this (cellstr)
in={'g','g','b','red','b','red','y'};
% the engine
[ix,ix]=ismember(in,tmpl(:,1));
col=cat(1,tmpl{ix(ix>0),2});
% the result
col

just a thought
us

Updates

1.0.0.0

- Much more efficient (and elegant?) code, thanks to Urs (us) Schwarz!

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Convert between RGB and Color Names