calculate and fill an area between a line and a curve

조회 수: 9 (최근 30일)
Enzo
Enzo 2022년 12월 11일
댓글: Paul 2022년 12월 14일
Hello everyone,
according to the following graph, I would like to fill and compute the area enclosed by the black line and the curve. I need to fill and compute the whole area, which is well under the zero for the curve)
for the line I have 4 points (x1,y1; x2, y2)
and for the curve I have 25.000 points (it's a LFP signal, close to an EEG).
Thanks for your help!

채택된 답변

Stephan
Stephan 2022년 12월 11일
편집: Stephan 2022년 12월 11일
A similar discussion here: https://de.mathworks.com/matlabcentral/answers/1870667-i-got-the-problem-with-polyshape-please-help-me. Once you have the polyshape object you can use the area function on it to calculate the enclosed area for example.
  댓글 수: 1
Enzo
Enzo 2022년 12월 14일
hello @Stephan unfortunately I wasn't able to achieve the goal. Could you provide some more tips?

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

추가 답변 (1개)

Paul
Paul 2022년 12월 11일
편집: Paul 2022년 12월 11일
Hi Enzo,
I think fill is what you might be looking for. Assuming that (x1,y1) and (x2,y2) are points on the blue data curve as suggested by the picture in the Question, then we can do this. If that assumption is incorrect, please provide more info on how the endpoints of the black segment relate to the data.
rng(100);
x = 1:25;
y = randn(1,25);
plot(x,y)
grid
x1 = x(7);y1=y(7);
x2 = x(9);y2=y(9);
hold on
plot([x1 x2],[y1 y2],'k','LineWidth',3)
fill([x(7:9)],[y(7:9)],'r')
polyshape and area to compute the area.
area(polyshape(x(7:9),y(7:9)))
ans = 2.2524
  댓글 수: 2
Enzo
Enzo 2022년 12월 14일
hello @Paul, It seems to not work for me.
Paul
Paul 2022년 12월 14일
Can you post relevant data and code to illustrate the problem that you're having?

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by