How to work out the length of a line
77 views (last 30 days)
Show older comments
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
Accepted Answer
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
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
More Answers (0)
See Also
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!