MATLAB: Explicitly specifying line colors when plotting a matrix

arraycolorMATLABplot

x = 1:3;
y = [1 2 3; 42 40 34];
plot(x,y,'Color', [0.5 0.5 0.5; 1 0 0])
produce an error:
Error using plot
Color value must be a 3 element numeric vector
Same with:
plot(x,y,'rg')
Error using plot
Error in color/linetype argument
This has bugged me for years, but I have circumvented it by unrolling the matrix into a number of vectors that I plot one at a time using whatever color I prefer. But is there no way to tell MATLAB (in a compact, readable form) what colors I would like it to use for whatever number of lines it will plot?

Best Answer

An alternative method would be to save the handles of the plotted data and set the colors via the array option of set. I find this method a lot less hassle than messing with ColorOrder and hold states:
x = 1:3;
y = [1 2 3; 42 40 34];
h = plot(x,y);
set(h, {'color'}, {[0.5 0.5 0.5]; [1 0 0]});
I often use the shortcut of using a colormap with num2cell to get the desired list of colors:
set(h, {'color'}, num2cell(jet(2),2));