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

조회 수: 1 (최근 30일)
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!

채택된 답변

Davide Masiello
Davide Masiello 2023년 8월 2일
편집: Davide Masiello 2023년 8월 2일
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
Rowan Quintero
Rowan Quintero 2023년 8월 2일
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 2023년 8월 2일
Fixed: The arrays were 1250x1 instead of 1x1250. thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by