Hey guys, I am quite new to MATLAB (2 weeks in) and have never coded before.
I have a task to produce a script that uses an nx2 array of coordinates, say x and y that correspond to the corners that form a boundary of a shape.
I want to code this so it calculates the total length of perimeter distance no matter what the input in the array is, for example a square could be:
Square =
00
30
33
03
So the perimeter would be 12, displayed to the user at the end. The last coordinate is the last corner before returning to the start. I can't use any built-in function that calculates co-ordinate distances or perimeters.
All advice even if newer than me would be great!
EDIT - I have done this so far, the input from the user:
clc
clear
n=input('How many Corners do you have?');
Corners = zeros (n,2);
for row=1:n
for column=1:2
usernumber=input('Enter the X and Y coordinates individually:');
Corners(row, column)=usernumber;
end
end
I am quite new to maths, so unsure on where to go from here.

답변 (2개)

Walter Roberson
Walter Roberson 2014년 3월 21일

0 개 추천

Euclidean distance is the standard sqrt((x2-x1)^2 + (y2-y1)^2)
Andrei Bobrov
Andrei Bobrov 2014년 3월 21일
편집: Andrei Bobrov 2014년 3월 21일

0 개 추천

xy=[0 0
3 0
3 3
0 3];
K = convhull(xy(:,1),xy(:,2));
out = sum(sqrt(sum(diff(xy(K,:)).^2,2)));

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

질문:

Tim
2014년 3월 20일

편집:

2014년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by