Cody

# Problem 42612. Convert ColorSpec string to RGB triplet

Solution 3177616

Submitted on 12 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   Fail
assert(isequal(str2rgb('m'),[1 0 1]))

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test2 (line 1) assert(isequal(str2rgb('m'),[1 0 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test3 (line 1) assert(isequal(str2rgb('c'),[0 1 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test4 (line 1) assert(isequal(str2rgb('r'),[1 0 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test5 (line 1) assert(isequal(str2rgb('g'),[0 1 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test6 (line 1) assert(isequal(str2rgb('b'),[0 0 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test7 (line 1) assert(isequal(str2rgb('w'),[1 1 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test8 (line 1) assert(isequal(str2rgb('k'),[0 0 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test9 (line 1) assert(isequal(str2rgb('yellow'),[1 1 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test10 (line 1) assert(isequal(str2rgb('magenta'),[1 0 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test11 (line 1) assert(isequal(str2rgb('cyan'),[0 1 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test12 (line 1) assert(isequal(str2rgb('red'),[1 0 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test13 (line 1) assert(isequal(str2rgb('green'),[0 1 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test14 (line 1) assert(isequal(str2rgb('blue'),[0 0 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test15 (line 1) assert(isequal(str2rgb('white'),[1 1 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test16 (line 1) assert(isequal(str2rgb('black'),[0 0 0]))

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

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test18 (line 1) assert(isequal(str2rgb('m'),[1 0 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test19 (line 1) assert(isequal(str2rgb('c'),[0 1 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test20 (line 1) assert(isequal(str2rgb('r'),[1 0 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test21 (line 1) assert(isequal(str2rgb('g'),[0 1 0]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test22 (line 1) assert(isequal(str2rgb('b'),[0 0 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test23 (line 1) assert(isequal(str2rgb('w'),[1 1 1]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test24 (line 3) assert(isequal(str2rgb(str(ii)),[]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test25 (line 1) assert(isequal(str2rgb('cyanide'),[]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 Error in Test26 (line 1) assert(isequal(str2rgb('yellowfin tuna'),[]))

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

Operands to the || and && operators must be convertible to logical scalar values. Error in str2rgb (line 2) if (str=='y' || str=='yellow')==1 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!