How can I connect the dots in my plot?

9 views (last 30 days)
Basically if I plot it 'x' it looks fine but if I plot '--' the lines connect in crazy pattern. What can I do?
Its really annoying me. I know that I can sort the data to match up with the correct points but to be honest I'm not sure how to do that.
please find attached source files and data,

Accepted Answer

Star Strider
Star Strider on 27 Aug 2016
Another approach:
D = load('Dustin Braun PL0Data (6).mat');
x = D.x;
y = D.y;
A = [x.^3 ones(size(x))];
p = A\y;
x1 = linspace(min(x), max(x))';
y1 = [x1.^3 ones(size(x1))]*p;
figure(1)
plot(x, y, 'o', x1, y1, '-r')
grid

More Answers (1)

Walter Roberson
Walter Roberson on 27 Aug 2016
[xs, xidx] = sort(x);
ys = y(xidx);
plot(xs, ys)
  1 Comment
Dustin Braun
Dustin Braun on 27 Aug 2016
I'm not really sure how this helps me. Could you please explain.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!