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

1 view (last 30 days)
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

Image Analyst
Image Analyst on 29 Nov 2013
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)

Roger Stafford
Roger Stafford on 29 Nov 2013
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.

Community Treasure Hunt

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

Start Hunting!