connected first and last points

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
plot(xi,yi,'r.');
n = n+1;
x(:,n) = xi;
y(:,n) = yi;
end
%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
plot(xs,ys,'r-');

 Réponse acceptée

Benjamin Schwabe
Benjamin Schwabe le 6 Fév 2012

0 votes

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.

3 commentaires

Adam
Adam le 7 Fév 2012
Yes thank you exactly what I had in mind. This works my plot ([xs, xs (1)], [y, y (1)], 'r-'), but if I add semicolons as the plot([xs;xs(1)],[ys;ys(1)],'r-'); in command windows it will write error: ??? Error using ==> vertcat CAT arguments dimensions are not Consistent.
Error in ==> point at 41 plot([xs;xs(1)],[ys;ys(1)],'r-');
I had a question about iterations, this line of the picture which would be positioned corp. What I was to target them, or council, of which I could based?
Benjamin Schwabe
Benjamin Schwabe le 7 Fév 2012
The one command with the ";" tries to add the next argument "below" the first one and the "," right to it. So, depending on the orientation row or column vector you require the one or the other. The not-working command will give you exactly the error you have quoted.
The other question you have: I don't get it...
Adam
Adam le 8 Fév 2012
Ook sorry wrong question. Once again thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by