Cody

# Problem 42613. Convert RGB triplet to ColorSpec string

Solution 2932255

Submitted on 10 Sep 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   Fail
rgb = [1 1 0; 1 0 1; 0 1 1; 1 0 0; 0 1 0; 0 0 1; 1 1 1; 0 0 0]; str = 'ymcrgbwk'; for ii=1:size(rgb,1) assert(isequal(rgb2str(rgb(ii,:)),str(ii))) end

Error: File: rgb2str.m Line: 2 Column: 10 Invalid syntax for calling function 'varargin' on the path. Use a valid syntax or explicitly initialize 'varargin' to make it a variable. Error in Test1 (line 11) assert(isequal(rgb2str(rgb(ii,:)),str(ii)))

2   Fail
rgb = [1 1 0; 1 0 1; 0 1 1; 1 0 0; 0 1 0; 0 0 1; 1 1 1; 0 0 0]; str = 'ymcrgbwk'; for ii=1:size(rgb,1) assert(isequal(rgb2str(rgb(ii,:),'short'),str(ii))) end

Error: File: rgb2str.m Line: 2 Column: 10 Invalid syntax for calling function 'varargin' on the path. Use a valid syntax or explicitly initialize 'varargin' to make it a variable. Error in Test2 (line 11) assert(isequal(rgb2str(rgb(ii,:),'short'),str(ii)))

3   Fail
rgb = [1 1 0; 1 0 1; 0 1 1; 1 0 0; 0 1 0; 0 0 1; 1 1 1; 0 0 0]; str = {'yellow','magenta','cyan','red','green','blue','white','black'}; for ii=1:size(rgb,1) assert(isequal(rgb2str(rgb(ii,:),'long'),str{ii})) end

Error: File: rgb2str.m Line: 2 Column: 10 Invalid syntax for calling function 'varargin' on the path. Use a valid syntax or explicitly initialize 'varargin' to make it a variable. Error in Test3 (line 11) assert(isequal(rgb2str(rgb(ii,:),'long'),str{ii}))

4   Fail
rng('default'); rgb = rand(8,3); for ii=1:size(rgb,1) assert(isequal(rgb2str(rgb(ii,:)),'')) end

Error: File: rgb2str.m Line: 2 Column: 10 Invalid syntax for calling function 'varargin' on the path. Use a valid syntax or explicitly initialize 'varargin' to make it a variable. Error in Test4 (line 4) assert(isequal(rgb2str(rgb(ii,:)),''))

5   Fail
rng(673); rgb = round(rand(8,3)*10)/10; for ii=1:size(rgb,1) assert(isequal(rgb2str(rgb(ii,:),'short'),'')) end

Error: File: rgb2str.m Line: 2 Column: 10 Invalid syntax for calling function 'varargin' on the path. Use a valid syntax or explicitly initialize 'varargin' to make it a variable. Error in Test5 (line 4) assert(isequal(rgb2str(rgb(ii,:),'short'),''))

6   Fail
rgb = round(rand(8,3)*10)/10; for ii=1:size(rgb,1) assert(isequal(rgb2str(rgb(ii,:),'long'),'')) end

Error: File: rgb2str.m Line: 2 Column: 10 Invalid syntax for calling function 'varargin' on the path. Use a valid syntax or explicitly initialize 'varargin' to make it a variable. Error in Test6 (line 3) assert(isequal(rgb2str(rgb(ii,:),'long'),''))

### Community Treasure Hunt

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

Start Hunting!