MATLAB: How to connect points with line segments

2d plotpolygons

I have a list of x and y values. I want to connect all points within a set distance of one another.
In other words, I would like to draw polygons from the vertices. I want to set a threshold above which the points will not be connected.
Next, when I have drawn the polygons, I would like to measure the angles formed between line segments.
Is this possible? Thank you so much.

Best Answer

As John said, what's the problem? Get the pairwise distance between all points, find the index of the pairs below your threshold, then plot:
x = randi([0 100], 100, 1); %random demo data
y = randi([0 100], 100, 1);
plot(x, y, '.'); %plot all points
distancethreshold = 5;
pairwisedist = hypot(x - x', y - y'); %or use pdist
[p1, p2] = find(tril(pairwisedist <= distancethreshold & pairwisedist > 0))
hold on;
indexpairs = [p1, p2]';
plot(x(indexpairs), y(indexpairs), '-r')