Calculate area between irregular unknown curve and straight line

1 view (last 30 days)
Hi,
I have a series of data that are trajectories of cursor movements. Below are some of the trajectories that I have.
I need to find the area between each trajectory and its ideal straight line trajectory (a straight line from the first point to the last point). Both the mouse trajectories and straight line have been normalized to have 101 sets of coordinates each. The trajectories always start from (0, 0) and go to the top left or right of the screen. I have attached the coordinates of the 2 trajectories and lines in an Excel file.
My question is: How do I find the area between the curves and the straight lines? I do not have the functions of the curves, so I can't use any of the integral functions. I have tried to use trapz with the y-coordinate as the independent variable, i.e.,
trapz(traject1_y, traject1_x) - trapz(str_line1_y, str_line1_x)
While it returns me a value, I'm not really sure how that value is derived; the Matlab documentation on trapz does not provide a lot of details. Moreover, my understanding is that the functions for integration require the independent variable to increase monotonically, and that isn't the case for me, as you can see from the plots that I have attached. Is there another way to find the area?
Thanks in advance!
  11 Comments
Abdallah Abu Aisha
Abdallah Abu Aisha on 4 Sep 2018
Hi Elin and Stijn, did you, by any chance, find a more "practical" way to find the sum of all areas between the two paths ( regardless positive or negative)? Since I am working on something very similar but for huge number of trips, so the solution proposed by Owaid doesn't work for my case. I have been struggling finding a function/code to solve this issue but all of them return only the "net" area. Best Regards, Abdallah
elin
elin on 12 Sep 2018
Hi Abdallah,
Unfortunately I did not manage to find such a method. But perhaps someone else reading this thread has done so?
Good luck!

Sign in to comment.

Accepted Answer

KSSV
KSSV on 6 Oct 2017
trapz(x,y) should work...
  1 Comment
elin
elin on 6 Oct 2017
Yup I realized that trapz and polyarea basically implements the same equation, although the way I was doing it like in the original thread would give a negative value. I now used trapz with x_area and y_area as the input arguments and it gave me the same answer as polyarea. Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!