How to plot point coordinates with connecting lines in between.

170 visualizaciones (últimos 30 días)
ivordes greenleaf
ivordes greenleaf el 13 de Abr. de 2015
Editada: pfb el 13 de Abr. de 2015
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!

Respuestas (2)

Chad Greene
Chad Greene el 13 de Abr. de 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 el 13 de Abr. de 2015
Editada: pfb el 13 de Abr. de 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,'.-')

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by