Shading an area between two intervals on a plot
62 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lui
el 8 de Ag. de 2020
Comentada: Star Strider
el 9 de Ag. de 2020
Hi everyone.
I have a vector of length 100 which I have plotted to yield a graph. I would like to shade the area under the graph segmented by the two lines using the area function.
I have tried the following code and it is unfortunate that it sheds the whole area. Any help will be appreciated.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/343480/image.png)
iz=linspace(15,20,6); % iz is the interval between the two xlines
yz=(FF(:,15:20)); % FF is the vector that generates the plot
area(iz,yz) % this should give me the area between two, shaded
Any corrections or better pointers are welcome.
2 comentarios
Respuesta aceptada
Star Strider
el 9 de Ag. de 2020
It is likely not possible to use area for this, since that is not how it was designed to be used.
Try this:
x = linspace(0, 100);
y = x.*exp(-0.07*x);
figure
plot(x, y)
q2 = ylim;
hold on
L = (x>15) & (x<20);
patch([x(L) fliplr(x(L))], [y(L), ones(1,nnz(L))*min(ylim)],'r')
hold off
grid
.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!