Fill area under a curve

477 visualizaciones (últimos 30 días)
Nikola
Nikola el 9 de Mzo. de 2023
Respondida: Dyuman Joshi el 9 de Mzo. de 2023
Is the right path to filling an area under a plot always area(X,Y)? Does it also work for more comlicated functions with hundres of plotting points?
  3 comentarios
John D'Errico
John D'Errico el 9 de Mzo. de 2023
@Nikola - since you already seem to know about area, why do you think it might not do what you want, since you seem to wonder if it will not work for you? Did you try something, and see something strange happen? Is there something confusing about the documentation for area that could perhaps be rectified? Please help us, so that we can better help you.
Nikola
Nikola el 9 de Mzo. de 2023
Its alright now, I kinda figured it out with the help of the people that answered (the community is amazing btw). The only thing I dont like about the 'area' function is that it doesnt seem to color the edges of the bottom part of the area.. Is there any way I can fix that?

Iniciar sesión para comentar.

Respuestas (2)

Arka
Arka el 9 de Mzo. de 2023
Hi,
Yes, you can use area to plot the area under the curves for functions. I was not sure what you meant by "complicated function", but I tried to demonstrate the example using a relatively complicated function and quite a few data points.
x = linspace(0,2, 10000000);
y = sqrt(x)+power(x, 1/3)+526.*sin(1./x);
area(x, y)

Dyuman Joshi
Dyuman Joshi el 9 de Mzo. de 2023
Coloring the edges at the bottom -
You might need to adjust y-limits to see the baseline properly in your figure.
x = 0:0.0001:10;
y = 50*sin(x).*cos(x)-25*sin(x)+75*cos(x);
p = area(x,y);
%Change the Line style of baseline
p.BaseLine.LineStyle = '--';
%Make baseline prominent
p.BaseLine.Color = [1 0 0];
p.BaseLine.LineWidth = 2.5;

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by