matlab把正弦和余弦函数图像画在一个图里面

来源:百度知道 编辑:UC知道 时间:2024/05/28 21:50:25
如题
如果可以的话,怎么把x,y轴也表示出来?
谢谢!

t=-5:0.01:5;
y1=sin(t);
y2=cos(t);
y3=0;
plot(t,y1,t,y2,t,y3,y3,t);
ylim([-2,2])
text(1,0.5403,'\leftarrowcos(x)');
text(2,0.9093,'\leftarrowsin(x)');
text(0,0,' 0');

t=0:0.1:10;
y1=sin(t);
y2=cos(t);
plot(t,y1,t,y2);

>> fplot(@sin,[-pi,pi])
>> hold on
>> fplot(@cos,[-pi,pi],'r')
>> legend('y=sin(x)','y=cos(x)')
>> grid on
>> hold off

用grid on 打开网格就包含x轴和y轴了,只不过是虚线,跟其他网格线一样。
如果非要画出x轴y轴,那就得另外再画了。