connected first and last points

20 views (last 30 days)
Hi I have a problem with the connected point. Use the mouse will add points to the picture and I link will successively, but the first and last point discontinuity will help someone? Thanks a lot in advance.
function [xs, ys, n, t] = bod
but = 1;
hold on
x = [ ];
y = [ ];%seznam vybranych bodu
n = 0;
% zobrazeni navodu pro vyber bodu
disp('Levym tlacitkem misi vkladate bod.')
disp('Pravym tlacitkem misi vložite posledni bod.')
but = 1;
while but == 1
[xi,yi,but] = ginput(1); %vlozi novy bod
n = n+1;
x(:,n) = xi;
y(:,n) = yi;
%inetrpolace podle krivky a jemnejsi radkovani
t = 1:n;
ts = 1:0.1:n;
ys = spline(t,y,ts);
xs = spline(t,x,ts);
% Graf interpolované krivky

Accepted Answer

Benjamin Schwabe
Benjamin Schwabe on 6 Feb 2012
Hello Adam,
I am not entirely sure that I understand your problem. You want to have line between the last and the first point, correct? Then you simply might consider changing the plot command to plot([xs,xs(1)],[ys,ys(1)],'r-');
If you have column vetors, this will not work, but the following code will: plot([xs;xs(1)],[ys;ys(1)],'r-');
I hope this solves your problem.
Adam on 8 Feb 2012
Ook sorry wrong question. Once again thank you

Sign in to comment.

More Answers (0)


Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!