Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how can we plot the data that we get from a for loop, just by joining the end points? I mean to say how can we form a closed figure? below is the code that i have done.

1 回表示 (過去 30 日間)
Rakesh
Rakesh 2013 年 12 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
%Asks the user, the number of vertices in their polygon fprintf('Enter The Number of vertices in your polygon\n'); n = input('n: ');
if n<3 %Check if the number of vertices is less than three or not fprintf('Wrong input, Please enter value greater than 2,Further calculation not possible exitting....'); exit(); end
%Asks the user for the coordinates of the vertices
fprintf('Enter The Coordinates of the polygon\n'); vertices=[];
for i = 1:n x = input('Enter the coordinate of x axis'); y = input('Enter the coordinate of y axis'); vertices=[vertices;x y]; end
%Prints the coordinates of the vertices fprintf('The coordinates you enter are\n'); vertices

回答 (1 件)

Jos (10584)
Jos (10584) 2013 年 12 月 5 日
Add the first point at the end so it becomes closed. After the loop:
Vxy = [vertices ; vertices(1,:)]
plot(Vxy(:,1), Vxy(:,2),'-')

この質問は閉じられています。

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by