Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB: Plotting help

  1. Jul 30, 2012 #1

    I have a dataset which traces out a circle. The issue is that the data points are not ordered, so if I plot the set and make lines between adjacent (= "adjacent" in the sense that they are next to eachother in the dataset) data points, then the plot does not look like a circle.

    Is there a way to plot data in MatLAB such that the points closest to eachother get marked up?

  2. jcsd
  3. Jul 30, 2012 #2


    User Avatar
    Science Advisor

    Hey Niles.

    Have you considered a routine that sorts the points based on their distance and relationship to other points?

    There is a technique that would work that sorts points for a convex polytype and this technique is called the convex hull: in 2D, the calculation is simplified using what is known as the Graham-Scan algorithm.

    If you have any set of points that describe the outline of a convex polytype (in n-dimensions), then this algorithm (if implemented in n-dimensions) will give you an oriented list of objects. For 2D, you can an ordered list of points, for 3D an ordered list of planes (triangles) and so on.

    See if someone has written a 2D convex hull algorithm for MATLAB, and check the computational geometry libraries in MATLAB, because convex-hull algorithms are basically computational geometry techniques, often used in scientific and game engine applications (as well as in rendering applications of any kind).
  4. Jul 30, 2012 #3


    Staff: Mentor

    if your points are in x,y form then perhaps by converting to polar to get the theta angle then use it as a key to sort your data in ascending theta order before plotting.

    You could plot without connecting a line between your points so that you get a dotted circle.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook