How to work out the length of a line

77 views (last 30 days)
I have a 'curved' line which is made up of 5 straight lines. How do I work out the total length of this line? Is this possible using a function in MATLAB.
  2 Comments
James Tursa
James Tursa on 2 Mar 2015
How are these lines represented in MATLAB?
J122
J122 on 2 Mar 2015
I have the x and y coordinates of each point and when plotted the connections create straight lines, all at different angles.

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 2 Mar 2015
Edited: James Tursa on 2 Mar 2015
% x = your x coordinate vector
% y = your y coordinate vector
% d = diff([x(:) y(:)]);
d = diff(your 3D point matrix); % EDIT
total_length = sum(sqrt(sum(d.*d,2)));
  7 Comments
Simon Schulte
Simon Schulte on 22 Feb 2017
What does this 'd.*d' do? I dont get the that point
James Tursa
James Tursa on 23 Feb 2017
Edited: James Tursa on 23 Feb 2017
d.*d does element-wise multiply ... i.e. it squares each value. Result is a matrix the same size as d. Could have gotten the same result with d.^2

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!