MATLAB: Is there anyway I can reduce this program to a few lines

cosine functionreduction

Hello,
I would like to reduce this program to 3 lines only or more but not explicit, Any ideas?
x1=-3*pi:0.1:-2*pi;
y1=-cos(x1);
x2=-2*pi:0.1:-pi;
y2=cos(x2);
x3=-pi:0.1:0;
y3=-cos(x3);
x4=0:0.1:pi;
y4=cos(x4);
x5=pi:0.1:2*pi;
y5=-cos(x5);
x6=2*pi:0.1:3*pi;
y6=cos(x6);
plot(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6)

Best Answer

x={-3*pi:0.1:-2*pi,
-2*pi:0.1:-pi,
-pi:0.1:0,
0:0.1:pi,
pi:0.1:2*pi,
2*pi:0.1:3*pi}.';
p=[x;cellfun(@(c,n)(-1)^n*cos(c),x,num2cell(1:6),'uni',0)];
plot(p{:})