rgb2str.m 380 B

123456789101112131415
  1. function [str] = rgb2str(c)
  2. % RGB2STR Utility function converts uisetcolor's RGB color to string
  3. % Usage:
  4. % str = rgb2str(c)
  5. % Input:
  6. % c = 1x3 float of RGB values between [0 1]
  7. % Output:
  8. % str = html color code format, e.g. color(23, 47, 83)
  9. %
  10. % Xiaohu Mo
  11. if isvector(c) && numel(c) == 3
  12. c = round(c * 255);
  13. str = sprintf('rgb(%d, %d, %d)', c(1), c(2), c(3));
  14. end