calculate and fill an area between a line and a curve

28 Ansichten (letzte 30 Tage)
Enzo am 11 Dez. 2022
Kommentiert: Paul am 14 Dez. 2022
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!

Akzeptierte Antwort

Stephan am 11 Dez. 2022
Bearbeitet: Stephan am 11 Dez. 2022
A similar discussion here: Once you have the polyshape object you can use the area function on it to calculate the enclosed area for example.
  1 Kommentar
Enzo am 14 Dez. 2022
hello @Stephan unfortunately I wasn't able to achieve the goal. Could you provide some more tips?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Paul am 11 Dez. 2022
Bearbeitet: Paul am 11 Dez. 2022
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.
x = 1:25;
y = randn(1,25);
x1 = x(7);y1=y(7);
x2 = x(9);y2=y(9);
hold on
plot([x1 x2],[y1 y2],'k','LineWidth',3)
polyshape and area to compute the area.
ans = 2.2524
  2 Kommentare
Paul am 14 Dez. 2022
Can you post relevant data and code to illustrate the problem that you're having?

Melden Sie sich an, um zu kommentieren.


Find more on 2-D and 3-D Plots 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!

Translated by