Calculate area between irregular unknown curve and straight line

조회 수: 1 (최근 30일)
elin
elin 2017년 10월 5일
댓글: elin 2018년 9월 12일
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
Abdallah Abu Aisha
Abdallah Abu Aisha 2018년 9월 4일
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 2018년 9월 12일
Hi Abdallah,
Unfortunately I did not manage to find such a method. But perhaps someone else reading this thread has done so?
Good luck!

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2017년 10월 6일
trapz(x,y) should work...
  댓글 수: 1
elin
elin 2017년 10월 6일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by