在两个不同点之间画线

时间:2014-05-07 11:42:14

标签: matlab matlab-figure

我有matlab,例如plot (sin(-pi:0.1:pi));非常好地绘制了曲线。现在我想连接两个点,即例如等于-1(= asin(-1))和pi的终点。

如何用一条线连接这些点?

注意:sin只是一个快速的样本。也许存在更好的功能,但我只想拥有一系列广泛的值(我在最后的结果 - 不是作为函数,而是作为数据点)。

1 个答案:

答案 0 :(得分:1)

您可以使用matlab中的line函数完成此操作,如下所示:

X = linspace(-pi,pi,100); % //use linspace to make sure the last point is pi
x = [asin(-1) pi]; % //define the set of points which define your line
y=[-1 eps]; % //Use epsilon here since sin(pi) is approx epsilon (The lines will look more connected )
plot (X,sin(X)); % //it is important to plot both X and Y, otherwise the x-axis will be wrong
hold on;line(x,y,'Color','r');

这会产生: enter image description here

相关问题