MATLAB: Create multiple figures of patches with random colors

colorfigurepatchrandom

I'm trying to create a number of patches with different colors using a random number function and all of the regular colors in MATLAB (i.e. g,r,b etc). I'm using a 'for' loop and assigning a new color to the patch each time but for some reason the script returns patches with the same color every time. The section of scripts i'm using now is:
for i=1:12
figure
col_list='ymcrgbk';
col=randi([1,7],1);
random_color=col_list(col);
patch_x=[0 2 2 0]
patch_y=[0 0 2 2]
final_color=['-' random_color]
patch(patch_x,patch_y,'final_color');
end

Best Answer

N = 12;
vec = 'ymcrgbk';
clr = vec(randi(numel(vec),N));
figure
for k = 1:N
X = [0,2,2,0]+k;
Y = [0,0,2,2];
patch(X,Y,clr(k));
end