Skip to content

Instantly share code, notes, and snippets.

@jnkather
Created June 8, 2015 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnkather/30f06c544a3dcb4e7388 to your computer and use it in GitHub Desktop.
Save jnkather/30f06c544a3dcb4e7388 to your computer and use it in GitHub Desktop.
Sort a Hex color vector by hue
% JN Kather 2015
% sorts a vector of hex colors by hue
% dependencies: needs functions rgb2hex and hex2rgb
dataDir = 'input/data/';
% read color vector
colorList = readtable(strcat(dataDir,'/custom_color_list3.txt'),...
'ReadVariableNames',false);
% preallocate
colors_HSV = zeros(numel(colorList),3);
% convert to HSV
for i=1:numel(colorList)
colors_HSV(i,:) = rgb2hsv(hex2rgb(char(colorList.Var1(i))));
end
% sort by hue
colors_HSV = sort(colors_HSV,1);
% convert back to Hex RGB
for i=1:numel(colorList)
colorsListOut(i) = cellstr(rgb2hex(hsv2rgb(colors_HSV(i,:))));
end
% print
disp(colorsListOut');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment