一是使用plot函数
画出两个向量的曲线,并将它们重叠在一起。这样可以清楚地看到两个向量之间的差异
x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
legend('sin(x)','cos(x)')
二是使用stem函数
构造两个向量的差异向量,用stem函数绘制差异向量的高度
x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = cos(x);
diff = y1 - y2;
plot(x,y1,x,y2);
hold on;
stem(x,diff);
legend('sin(x)','cos(x)','difference');
三是bar函数
绘制差异向量的条形图
x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = cos(x);
diff = y1 - y2;
plot(x,y1,x,y2);
hold on;
bar(x,diff);
legend('sin(x)','cos(x)','difference');