目录
叠加阶梯图和线图
此示例演示如何在阶梯图上叠加线图。定义要绘图的数据。
alpha = 0.01;
beta = 0.5;
t = 0:10;
f = exp(-alpha*t).*sin(beta*t);
将 f 显示为阶梯图。使用 hold 函数保留阶梯图。使用带有星形标记的虚线添加 f 线图。
stairs(t,f)
hold on
plot(t,f,'--*')
hold off
如图所示:
使用 axis 函数设置坐标轴范围。标记 x 轴并向图形添加一个标题。
axis([0,10,-1.2,1.2])
xlabel('t = 0:10')
title('Stairstep plot of e^{-(\alpha*t)} sin\beta*t')
如图所示:
合并线图和针状图
此示例演示如何合并一个线图和两个针状图。然后,显示如何添加标题、坐标轴标签和图例。
创建数据并绘制一条线条。
x = linspace(0,2*pi,60);
a = sin(x);
b = cos(x);
plot(x,a+b)
在坐标区中添加两个针状图。使用 hold on 防止新绘图替换现有的绘图。
hold on
stem(x,a)
stem(x,b)
hold off
添加标题、坐标轴标签和图例。按照创建绘图的顺序指定图例说明。
title('Linear Combination of Two Functions')
xlabel('Time in \musecs')
ylabel('Magnitude')
legend('a+b','a = sin(x)','b = cos(x)')