How is possible to join dots of a scatter plot after plotting, and make a line from a dotted plot?
I'm guessing you generated a scatter plot from x
and y
coordinates by,
plot(x,y,'.');
Join them with
plot(x,y,'.');
hold on;
plot(x,y,'-');
Or in one command
plot(x,y,'.-');
Is this what you wanted?
If you have an existing plot as a scatter plot, you cannot simply just join the dots without knowing which points are connected to which others.
If you know the order/connectivity of the points, then you could simply have used the plot function to do that in the first place. The call
plot(x,y,'-')
will connect the dots with straight line segments. If you wish to use a marker symbol at each point along the line, then you can add one of the markers that plot allows, as this:
plot(x,y,'o-')
You can get a list of the allowed markers from
help plot
If you have used scatter on a set of points, and now wish to overlay a line connecting the points, then use the hold function to force matlab to plot on top of the scatter plot. For example,
scatter(x,y)
hold on
plot(x,y,'-')
hold off
Again, any of these variations require you to know the connectivity between the points. There are some schemes that can sometimes work to recover that connectivity from a list of isolated points. One of these methods is called CRUST, often used for 3-d surface reconstruction. I found many references by a simple search for "crust algorithm".
If you have a scatterplot (made with the scatter function I suspect) and for some reason don't want to redraw it with plot, here is what you can do to connect the dots:
h = findobj(gca,'type','hggroup');
hold on
for k=1:numel(h)
x = get(h(k),'xdata');
y = get(h(k),'ydata');
plot(x,y,'-')
end
hold off
The dots will be connected by their original order. If you want you can sort the data before plot, for example by x:
[x,ind] = sort(x);
y = y(ind);