How would I generate an n-sided shape wher n >= 4

Hello all,
I'm new to Matlab but I know a bit about programming.
For class, we have been asked to generate a matrix that gives the vertices of a two dimensional n-sided shape where n>=4. Then, generate the vectors to connect the vertices. We were also given a hint: a vector for each segment can be found by adding the vectors drawn from the origin to each of two adjacent vertices.
I know how to create a matrix using A = [1 1; 1 2; 2 2; 2 1] but I'm not sure how to draw the vectors given this or any other matrix.
The plot() function looks promising, but I'm unsure how to use it with the matrix.
Thank you for any suggestions.
Btw, I'm using 2011a

 Accepted Answer

If the first column of A contains the x coordinates, and the y are in the second column:
plot(A(:,1), A(:,2), 'bo-', 'LineWidth', 2, 'MarkerSize', 10);
grid on;

More Answers (1)

That hint "a vector for each segment can be found by adding the vectors drawn from the origin to each of two adjacent vertices" is incorrectly stated. Replace the word 'adding' by 'subtracting'. If P1 and P2 are two points (each represented by an array of two elements,) the vector pointing from P1 to P2 is P2-P1.

1 Comment

Yes, you're right. That part had me confused. Thanks.

Sign in to comment.

Categories

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

Asked:

Jim
on 29 Nov 2013

Commented:

Jim
on 29 Nov 2013

Community Treasure Hunt

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

Start Hunting!