How do I shade the area between two curves on a plot that is generated by arrays?

2 visualizaciones (últimos 30 días)
For example:
x1 = [ 1 2 3 ];
y1 = [2 5 8];
x2 = [1 2.5 3.5];
y2 = [1 6 3];
plot(x1, y1)
hold on
plot(x2, y2)
Thanks for the help!

Respuesta aceptada

Davide Masiello
Davide Masiello el 2 de Ag. de 2023
Editada: Davide Masiello el 2 de Ag. de 2023
Use the patch function.
x1 = [1 2 3];
y1 = [2 5 8];
x2 = [1 2.5 3.5];
y2 = [1 6 3];
hold on
patch([x1 flip(x2)], [y1 flip(y2)],'y','EdgeColor','none')
plot(x1, y1,'b')
plot(x2, y2,'r')
box on
axis padded
  4 comentarios
Rowan Quintero
Rowan Quintero el 2 de Ag. de 2023
I am getting the error:
"error in horzcat:
dimensions in array being concatenated are not consistent"
Any ideas? I appreciate your responsiveness.
Rowan Quintero
Rowan Quintero el 2 de Ag. de 2023
Fixed: The arrays were 1250x1 instead of 1x1250. thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scatter Plots 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