connecting every two endpoints

Hi all, I have the following formula that allow me to plot 2D points calculated from a text file.
plot(endpnts(:,1),scyendpnts,'sr', 'MarkerSize',5,'MarkerFaceColor', 'b', 'MarkerEdgeColor', 'none'); %plot all endpoints a red dots
plot(endpnts(R,1),scyendpnts(R),'sr', 'MarkerSize',5, 'MarkerFaceColor', 'b', 'MarkerEdgeColor', 'none');
I'm trying to also connect the points two by two with a line, like (4:1) with (5:1), (6:1) with (7:1) and so on but can't figure out how - by using the statement bellow I can draw a line between all points.
hold on;
plot(endpnts(:,1),scyendpnts,'LineWidth',2, 'MarkerFaceColor','b');
plot(endpnts(R,1),scyendpnts,'LineWidth',2, 'MarkerFaceColor','b')
I thank you in advance
Tarsis

 Risposta accettata

plot(endpnts(:,1),scyendpnts,'sr', 'MarkerSize',5,'MarkerFaceColor', 'b', 'MarkerEdgeColor', 'none');
is enough to draw lines between each pair of points, with red square markers.
I am not sure what more you want done? Do you want a line connecting the last point to the first? If so then
plot(endpoints([1:end 1],1), scyendpnts([1:end 1]), 'sr', 'MarkerSize',5,'MarkerFaceColor', 'b', 'MarkerEdgeColor', 'none');
Are you trying to connect every point to every other point, so point 4 is connected to point 1, 2, 3, 5, 6, etc?

5 Commenti

tarsis
tarsis il 12 Nov 2013
Hi Walter,
Thank you so much for your anwser! I'm trying to connect point 4 to point 5, point 6 to point 7 and so on.
But not between those (there should be no connection between 5 and 6, 7 and 8, etc).
Thank again.
x = reshape(endpnts(:,1), 2, []);
y = reshape(scyendpnts, 2, []);
plot(x, y, 'sr', 'MarkerSize',5,'MarkerFaceColor', 'b', 'MarkerEdgeColor', 'none');
tarsis
tarsis il 12 Nov 2013
Hi Walter, thanks a lot.
Just one more question, is there a way for this plot start from endopoint 4 instead of 1?
Thank a lot
Tarsis
x = reshape(endpnts(4:end,1), 2, []);
y = reshape(scyendpnts(4:end), 2, []);
Just watch out that the number of remaining points is even (so the number of original points must be odd); if it is not then the above code will crash trying to match up the last entry.
tarsis
tarsis il 13 Nov 2013
Awesome, thanks again.

Accedi per commentare.

Più risposte (1)

Seyedfarid Ghahari
Seyedfarid Ghahari il 27 Apr 2017

0 voti

Hi,
Is there any automatic way to connect points to each other as 1 to 2, 3 to 4, 5 to 6, ... without using for. In other words, I have Xi, Yi, Zi and Xj, Yj, and Zj vectors which contain X, Y, and Z coordinates of start (i) and end (j) of many lines. I would like to draw these lines, but if I use:
plot3([Xi,Xj],[Yi,Yj],[Zi,Zj])
Matlab connects all lines, while I want to have all lines disconnected!

2 Commenti

That is what my answer above does: reshape into columns of length 2, and MATLAB will draw each column as a distinct line.
By doing this, all points are connected in series. That is, 1 is connected to 2, 2 to 3, 3 to, ... while I do not want any connection between 2 and 3 or between 4 and 5 etc. I figured it out: I used NaN at every two points;)

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by