Cody

Problem 42613. Convert RGB triplet to ColorSpec string

Solution 2179074

Submitted on 28 Mar 2020 by Asif Newaz
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
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

str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array

2   Pass
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

str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array

3   Pass
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

str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array

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

str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array

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

str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array

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

str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array str = 0×0 empty char array

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!