?? exm03132_2.m
字號:
%exm03132_2.m
t=linspace(0,3*pi,500);y=sin(t); %產生正弦波
%處理方法一,從自變量入手進行逐段處理
z1=((t<pi)|(t>2*pi)).*y; %獲得整流半波
w=(t>pi/3&t<2*pi/3)+(t>7*pi/3&t<8*pi/3);%關系邏輯運算和數值運算
w_n=~w;
z2=w*sin(pi/3)+w_n.*z1; %獲得削頂整流半波
shg,subplot(1,3,1),plot(t,y,':r'),ylabel('y')
subplot(1,3,2),plot(t,z1,':r'),axis([0 10 -1 1])
subplot(1,3,3),plot(t,z2,'-b'),axis([0 10 -1 1])
disp('按任意鍵,繼續!'),pause
%處理方法二,從函數值入手進行逐段處理
z=(y>=0).*y; %正弦整流半波
a=sin(pi/3);
z=(y>=a)*a+(y<a).*z; %削頂的正弦整流半波
clf
plot(t,y,':r');hold on;plot(t,z,'-b')
xlabel('t'),ylabel('z=f(t)'),title('逐段解析函數')
legend('y=sin(t)','z=f(t)',4),hold off
disp('結束')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -