Trying to find area under my plot

조회 수: 3 (최근 30일)
Arya patwardhan
Arya patwardhan 2022년 11월 28일
편집: Torsten 2022년 11월 29일
I have plotted my data (two vectors of size 300x1 each) and it looks like this (see attachment):
I have tried to use trapz to get my area and get a value of around 46.
Looking at the graph, I can tell this area is wrong. Very roughly it should be around 12
So how do i get my area to equal to 12?
Thanks for any help
  댓글 수: 1
Arya patwardhan
Arya patwardhan 2022년 11월 28일
I would also like to be able to find the postive and negative area's

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

답변 (2개)

Torsten
Torsten 2022년 11월 28일
편집: Torsten 2022년 11월 28일
To get the positive and negative areas separately, cut your closed curve at the two positions where it passes the x-axis and take the line connecting these two points on the x-axis to close the upper and lower curves.
n = 100;
I = linspace(0,1,n);
x = cos(2*pi*I);
y = sin(2*pi*I);
polyarea(x,y)
ans = 3.1395
pi
ans = 3.1416

John D'Errico
John D'Errico 2022년 11월 28일
You don't give your data. You show only a plot. So make a polyshape of it. Then compute the area.
t = linspace(0,2*pi,50);
x = cos(t);
y = sin(t);
x(end) = [];
y(end) = [];
ps = polyshape(x,y);
area(ps)
ans = 3.1330
As you can see, this is just unit curcle, so the area would be pi, at least if we had more points.
plot(ps)
hold on
plot(x,y,'o')
axis equal
grid on
  댓글 수: 2
Arya patwardhan
Arya patwardhan 2022년 11월 28일
Hi i tried using your method and sadly it did not work.
It give me this error: Polyshape has duplicate vertices,intersection,or other inconsisentices.
It give me an answer of 0
I have attached my data in the attached excel file
Thank you in advance for you help and patience
Torsten
Torsten 2022년 11월 29일
편집: Torsten 2022년 11월 29일
I'd cover the area of interest by a fine enough mesh of squares and count them.
I think this will be more reliable than to use polyarea to the dataset that you included.
The other alternative is to work on your data so that you extract a sequence of points that don't overlap and repeat and that represent the upper and low part of your area, respectively.

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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by