shade area between two yline

조회 수: 35 (최근 30일)
Ham Man
Ham Man 2022년 8월 30일
댓글: Ham Man 2022년 8월 31일
I want to shade the area between two yline:
p1 = yline(5,'-','color',[177 177 177]./255,'LineWidth',2);hold on
p2 = yline(4,'-','color',[177 177 177]./255,'LineWidth',2);hold on
x = 0:2200;
x2 = [x, fliplr(x)];
inBetween = [p1, fliplr(p2)];
fill(x2, inBetween, 'gray');hold on;
Since x2 and inbetween are not in the same size, my code does not work. How can I change it to gt the shaded area?
Thank you for any help

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 30일
You cannot fill between yline() or xline().
yline() and xline() are reference lines that cross the entire axes and logically continue to +/- infinity. If you pan or zoom, yline() and xline() continue to be shown even if there is no data in the new area.
fill(), however, is always implemented as a closed bounded area -- something that can zoom or pan away.
I suggest you
fill(x([1 end end 1 1]), [4 4 5 5 4], 'gray')
  댓글 수: 3
Walter Roberson
Walter Roberson 2022년 8월 30일
편집: Walter Roberson 2022년 8월 30일
x = sort(rand(1,20));
fill(x([1 end end 1 1]), [4 4 5 5 4], [.8 .8 .8])
Ham Man
Ham Man 2022년 8월 31일
Thank you so much Walter! It works well

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

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 8월 30일

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by