Cody

# Problem 42612. Convert ColorSpec string to RGB triplet

Solution 3343713

Submitted on 23 Oct 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
assert(isequal(str2rgb('y'),[1 1 0]))

2   Pass
assert(isequal(str2rgb('m'),[1 0 1]))

3   Pass
assert(isequal(str2rgb('c'),[0 1 1]))

4   Pass
assert(isequal(str2rgb('r'),[1 0 0]))

5   Pass
assert(isequal(str2rgb('g'),[0 1 0]))

6   Pass
assert(isequal(str2rgb('b'),[0 0 1]))

7   Pass
assert(isequal(str2rgb('w'),[1 1 1]))

8   Pass
assert(isequal(str2rgb('k'),[0 0 0]))

9   Pass
assert(isequal(str2rgb('yellow'),[1 1 0]))

10   Fail
assert(isequal(str2rgb('magenta'),[1 0 1]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test10 (line 1) assert(isequal(str2rgb('magenta'),[1 0 1]))

11   Fail
assert(isequal(str2rgb('cyan'),[0 1 1]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test11 (line 1) assert(isequal(str2rgb('cyan'),[0 1 1]))

12   Fail
assert(isequal(str2rgb('red'),[1 0 0]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test12 (line 1) assert(isequal(str2rgb('red'),[1 0 0]))

13   Fail
assert(isequal(str2rgb('green'),[0 1 0]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test13 (line 1) assert(isequal(str2rgb('green'),[0 1 0]))

14   Fail
assert(isequal(str2rgb('blue'),[0 0 1]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test14 (line 1) assert(isequal(str2rgb('blue'),[0 0 1]))

15   Fail
assert(isequal(str2rgb('white'),[1 1 1]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test15 (line 1) assert(isequal(str2rgb('white'),[1 1 1]))

16   Fail
assert(isequal(str2rgb('black'),[0 0 0]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test16 (line 1) assert(isequal(str2rgb('black'),[0 0 0]))

17   Pass
assert(isequal(str2rgb('y'),[1 1 0]))

18   Pass
assert(isequal(str2rgb('m'),[1 0 1]))

19   Pass
assert(isequal(str2rgb('c'),[0 1 1]))

20   Pass
assert(isequal(str2rgb('r'),[1 0 0]))

21   Pass
assert(isequal(str2rgb('g'),[0 1 0]))

22   Pass
assert(isequal(str2rgb('b'),[0 0 1]))

23   Pass
assert(isequal(str2rgb('w'),[1 1 1]))

24   Pass
str = 'adefhijlnopqstuvxz'; for ii=1:length(str) assert(isequal(str2rgb(str(ii)),[])) end

25   Fail
assert(isequal(str2rgb('cyanide'),[]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test25 (line 1) assert(isequal(str2rgb('cyanide'),[]))

26   Fail
assert(isequal(str2rgb('yellowfin tuna'),[]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test26 (line 1) assert(isequal(str2rgb('yellowfin tuna'),[]))

27   Fail
assert(isequal(str2rgb('blue jays'),[]))

Matrix dimensions must agree. Error in str2rgb (line 2) if(str=='y' | str=='yellow') Error in Test27 (line 1) assert(isequal(str2rgb('blue jays'),[]))

### Community Treasure Hunt

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

Start Hunting!