MATLAB: How to get matlab to draw lines between points

MATLABplotplotting

Basically, I have to draw a pentagram. I've got the points, I just need the lines to be drawn between them. Here's my code so far:
axis equal
r = input('Enter the distance from the origin: ');
while r < 0
r = input('The distance must be greater than 0: ');
end
angle = linspace(0,2*pi,6);
x = r*sin(angle);
y = r*cos(angle);
plot(x(2),y(2),x(5),y(5),'or-',x(5),y(5),x(3),y(3),'or-',x(3),y(3),x(6),y(6),'or-',x(6),y(6),x(4),y(4),'or-',x(4),y(4),x(2),y(2),'or-')
I don't understand why adding the "-" part of 'or-' isn't making the lines show up.

Best Answer

To draw pentagram, the latter half of your script should be:
angle = linspace(0,2*pi,6);
x = r*sin(angle);
y = r*cos(angle);
idx = mod((1:2:12), 5) + 1;
plot(x(idx),y(idx),'or-');
Related Question