Matlab Code – Change color of data points for each subject/group

This came about because I wanted to make a bar graph from a data set. In these data, each of my seven subjects contributed multiple data points. I wanted each bar that corresponded to a subject to be a unique color. I couldn’t find it anywhere online so here is a routine to accomplish it with either subjects as a cell array or numerical array. Note: You must have Matlab 2018a or greater. Otherwise you will get a CData error. 

matlab bar graph unique subject colors hsv
Cell array example
matlab bar graph unique subject colors gray
Numerical array example
Example of real data – Cyan subject tends to try for a long time before quitting. 

 

Creative Commons License
This work by Blake Porter is licensed under a Creative Commons Attribution-Non Commercial-ShareAlike 4.0 International License

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.