Say, for example, I had …
x = [1 1 2 2];
y = [1 2 2 1];
plot(x, y, 'b-');
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?
I’m also pulling in lines of text with points, so simply adding another point 1,1 is not an option.
impolycan be useful, however, it creates a modifiable curve which is slower than plot.You can write a simple function for that:
By the way, the
(:)colon operator is used as defensive programming means. In this way,xandycan be either row or column vectors.The
vararginallows using additional parameters, like: