How do I calculate the distance between x1,x2,y1,y2?

2 views (last 30 days)
I have an excel datasheet and I want to calculate the distances using a simple distance formula (square root of (x2-x1)^(2)+(y2-y1)^(2)). How can I open it in Matlab and how can i calculate it in Matlab?

Answers (1)

Image Analyst
Image Analyst on 4 Jul 2016
Try this:
numbers = xlsread(filename)
x1 = numbers(:, 4); % Extract column 4
y1 = numbers(:, 5); % Extract column 5
x2 = numbers(:, 6); % Extract column 6
y2 = numbers(:, 7); % Extract column 7
distances = sqrt((x2-x1).^2 + (y2-y1).^2);
  2 Comments
Thooba Samimi
Thooba Samimi on 4 Jul 2016
does this calculate the distance for each position? Also when I type numbers=xlsread(DelmarvaS_SVA_LT) it says "Undefined function or variable 'DelmarvaS_SVA_LT'."
Image Analyst
Image Analyst on 4 Jul 2016
Edited: Image Analyst on 4 Jul 2016
Try
numbers=xlsread('DelmarvaS_SVA_LT.xlsx')
and distances does give you the distance for each row in the workbook.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!