Hi, I have a task to write a function that asks the user for the coordinates of a triangle and I have to calculate the distance between two points. I have to find area too.

1 view (last 30 days)
function d = calculateDistance(x1, y1, x2, y2)
%Purpose: Calculates the distance between two points of a triangle
% d = calculateDistance(x1, y1, x2, y2)
d = sqrt((x2 - x1)^2 + (y2 - y1)^2);
end
  1 Comment
Pranav
Pranav on 28 Feb 2023
This is what I have written, and I am getting an error as follows:
Not enough input arguments.
Error in calculateDistance (line 4)
d = sqrt((x2 - x1)^2 + (y2 - y1)^2);
Please can someone help me resolve this issue.
Thanks.

Sign in to comment.

Answers (2)

Cris LaPierre
Cris LaPierre on 28 Feb 2023
Edited: Cris LaPierre on 28 Feb 2023
Show us the code you are using to call your function as well. Based on the error message, you are not calling it with 4 inputs arguments. You should be doing something like this
d = calculateDistance(1, 3, 7, 5)
The error points to line 4 because that is where you use the input variables, and some of them have not been defined/assigned a value.

Image Analyst
Image Analyst on 28 Feb 2023
Try polyarea and pdist2. pdist2 will find all the distance between all 3 points, while polyarea will give you the area.

Categories

Find more on Computational Geometry in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!