MATLAB: How to use same colors inn all figures when making several figures with a loop

loop color

I have created a loop that makes several figures. When I apply "rand(1,3)) in the loop below, each figure gets different colors. Do you know how I can change the loop below to so that the colors are the same in every figure?
Alder = {'<20', '2029','3039','4049','5059','6069','>70', 'all'};
Vars = {gjG, gjR, gjI, gjDI, gjBV, GtoDI, GtoBV, RtoDIplusR, ItoG, RtoG, GtoI};
Vars2 = {'gjG', 'gjR', 'gjI', 'gjDI', 'gjBV', 'GtoDI', 'GtoBV', 'RtoDIplusR', 'ItoG', 'RtoG', 'GtoI'};
Aar = {'2011', '2012', '2013_1', '2014_1', '2014_s2', '2014_s5'};
n = length(Vars);
nAar = length(Aar);
for iVars = 1:n;
aVars = Vars{iVars};
figure,title(Vars2{iVars});
hold on
for iAar = 1:nAar
plot(aVars(11,:,iAar), 'color', rand(1,3));
set(gca, 'XTickLabel',Alder)
legend((Aar),'location','NE','FontSize',10);
end
hold off
end

Best Answer

This line sets the color:
plot(aVars(11,:,iAar), 'color', rand(1,3))
You could change that to
plot(aVars(11,:,iAar), 'color', 'r')
for red, or
plot(aVars(11,:,iAar), 'color', [r g b])
where r,g, and b are numeric values to give any RGB color.