Z=[3 1 7];
for i=1:length(Z)
A(i)=Z(i)+2;
B(i)=Z(i)-7;
C(i)=Z(i)+4;
col=['g' 'b' 'r'];
legendtext = ['a' 'b' 'c']; %%Add your legend text
for j=1:length(col)
x=[1 2 3];
y(:,i)=[A(i) B(i),C(i)];
subplot(3,1,i);
plot(x,y(:,i),'color',col(i))
legend(legendtext(i));
end
end