说,例如,我有...
Say, for example, I had ...
x = [1 1 2 2];
y = [1 2 2 1];
plot(x, y, 'b-');
我将获得与连接点(1,1),(1,2),和(2,2)线的曲线图。有没有什么办法的最后一点与第一连接,从而完成了广场上的情节?
I will get a plot with lines connecting the points (1,1), (1,2), and (2,2). Is there any way to connect the final point with the first, thus completing the square on the plot?
我也拉动文本分线,因此只需添加另一点1,1是不是一种选择。
I'm also pulling in lines of text with points, so simply adding another point 1,1 is not an option.
impoly
可能是有用的,但是,它创建了一个修改的曲线比剧情更慢。
impoly
can be useful, however, it creates a modifiable curve which is slower than plot.
您可以编写一个简单的函数,该函数:
You can write a simple function for that:
function plotc(x,y,varargin)
x = [x(:) ; x(1)];
y = [y(:) ; y(1)];
plot(x,y,varargin{:})
end
顺便说一句,在(:)
冒号运算符是用来作为防御性编程手段。通过这种方式, X
和是
可以是行或列向量。
By the way, the (:)
colon operator is used as defensive programming means. In this way, x
and y
can be either row or column vectors.
在 varargin
允许使用额外的参数,如:
The varargin
allows using additional parameters, like:
plotc(x,y,'Color','r');
plotc(x,y,'Parent',a,'LineWidth',2);