MATLAB: How to convert True Color format data to RGB vector format data and the other way around

colorconversionconvertconvertingdatadec2hexformathex2decMATLABrgbtrue

I would like to convert True Color data to RGB vector color data and back. MATLAB Graphics mainly use RGB vectors as color data while Excel applications for example use True Color format.
I would like to know how to convert between those two formats.

Best Answer

There is no built-in method to convert between True Color format and RGB vector format.
However you can easily convert because both formats are basically the same, just the numerical representation is different.
To convert an RGB array to True Color format use the following code:
truecol = hex2dec(sprintf(dec2hex(255*flipdim(rgb,2))'));
To convert a True Color number to RGB vector format use the following code:
rgb = mod([truecol floor(truecol/256) floor((truecol)/256^2)],256) /255;
Related Question