clear                                %清除变量
thetha=0:0.01:3*pi;y=sin(thetha);    %生成正弦波数据
y11=((thetha<pi)|(thetha>2*pi)).*y;  % 获得正半轴的整流半波
y12=((thetha>pi)&(thetha<2*pi)).*-y; %负半轴的半波变成正波形
y1=y11+y12;                          %获得全波整流波形
Q=(thetha>pi/3&thetha<2*pi/3)+...    %确定削顶处为1   
 (thetha>4*pi/3&thetha<5*pi/3)+(thetha>7*pi/3&thetha<8*pi/3);
P=~Q;                    % 削顶处取反
y2=Q*sin(pi/3)+P.*y1;    %获得削顶全波整流波形
subplot(5,1,1)           %将当前图形窗口分隔为5行1列在第1区域画图    
plot(thetha,y)           %画正弦波图
axis([0,10,-1.2,1.2])    %标注横纵坐标轴
ylabel('y'),grid on      %纵轴标标变量‘y’，在图形中开启网格 
subplot(5,1,2),plot(thetha,y1),axis([0,10,-0.2,1.2]),ylabel('y1'),grid on
subplot(5,1,3),plot(thetha,Q),axis([0,10,-0.2,1.2]),ylabel('Q'),grid on
subplot(5,1,4),plot(thetha,P),axis([0,10,-0.2,1.2]),ylabel('P'),grid on
subplot(5,1,5),plot(thetha,y2),  %画削顶全波整流图
axis([0,10,-0.2,1.2]),xlabel('thetha'),ylabel('y2'),grid on