Finding out the Line Length of a fast signal
Show older comments
Hi,
I'm trying to compare a set of spike-wave data. What I want to be able to do it set up a start point and an end point in my data series and calculate the length of the graph line between these two points. Basically it's like having a length of string curled up on your desk, grabbing the ends with your fingers and pulling until the length of string is taut. The idea being you would then measure the length of string.
I'm new to matlab, and have no idea how to tackle this. So any help would be really appreciated.
Thanks
1 Comment
Matt Kindig
on 18 Oct 2012
Edited: Matt Kindig
on 18 Oct 2012
So to clarify, you just need to calculate the straight-line (Euclidean) distance between two points? If you have the coordinates of the points, you can do this simply as:
%(x1,y1) and (x2,y2) are the coordinates of the points
dist = sqrt((x1-x2).^2+(y1-y2).^2); %this is the line length
Or are you trying to get the length of the line as you trace along the plot (basically the arc length of the curve)? If so, you do essentially the same thing, but instead of calculating the distance between the start and end points, you calculate between each pair of adjacent points (i.e. each segment), and then sum the lengths. Something like this:
%x and y are vectors containing the coordinates of the points
% (in order) between the start and end points
dx = diff(x); %incremental difference between x coordinates
dy = diff(y); %incremental difference between y coordinates
dL = sqrt(dx.^2+dy.^2); %length of each segment
dist = sum(dL); %total line length
Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!