How to plot point coordinates with connecting lines in between.

161 views (last 30 days)
So I have a set of point coordinates with a line connects between them, I am not sure about the command to plot those points.
This is what I have:
x(1) = (-5.3185, -2.302585);
x(2) = (-10.0332, -4.6052);
x(3)= (-14.6496, -6.9078);
x(4)=(-19.2959,-9.2103);
plot(x(1),x(2),x(3),,x(4), '*-')
Thanks for any input!

Answers (2)

Chad Greene
Chad Greene on 13 Apr 2015
x(1) refers to only the first element in some variable x, and similarly, x(2) refers to only the second element. So you can't assign two values to x(1) as you've tried to do with
x(1) = (-5.3185, -2.302585);
One way to do it is to assign x and y values separately:
x = [-5.3185 -10.0332 -14.6496 -19.2959];
y = [-2.302585 -4.6052 -6.9078 -9.2103];
plot(x,y, '*-')

pfb
pfb on 13 Apr 2015
Edited: pfb on 13 Apr 2015
that's not matlab syntax. Reading the documentation of "plot" is a good idea here. Type doc plot (enter)
Anyway, you should build vectors with the abscissae and the ordinates (using square parentheses)
x = [-5.3185 -10.0332 -14.6496 ...];
y = [...];
and then simply
plot(x,y)
or
plot(x,y,'.-')

Community Treasure Hunt

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

Start Hunting!