필터 지우기
필터 지우기

Color background between two ylines patch (datetime)

조회 수: 7 (최근 30일)
Lieke Numan
Lieke Numan 2019년 3월 15일
댓글: Star Strider 2019년 3월 18일
I have a plot with heartrate over time, using a datetime function. In addition I have two ylines (y=60 and y=100). Now I want to color the area (background) between those y-lines, for my whole timeline using datetime. The function patch does not work, as it cannot deal with datetime functions. How can I do this?
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2019년 3월 15일
Lieke - can you provide a screen shot of what you have and what you want coloured in? I don't understand how the datetime function is an issue since you just want to color the area between those y-lines. Aren't the y-lines just y=60 and y=100?

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

채택된 답변

Star Strider
Star Strider 2019년 3월 15일
The error is:
Error using patch
Non-numeric data is not supported in 'patch'
So you can’t use it with datetime objects.
If you want a single vertical line, just use plot:
datetime1=datetime('18-Aug-2017 22:56:00');
datetime2=datetime('18-Aug-2017 23:56:00');
figure
plot([datetime1 datetime1],[50 100],'red')
ylim([40 150])
set(gca, 'XTickLabelRotation',45)
Experiment to get the result you want.
  댓글 수: 6
Lieke Numan
Lieke Numan 2019년 3월 18일
That works perfectly, thanks!
Star Strider
Star Strider 2019년 3월 18일
My pleasure.
If my Answer helped solve your problem, please Accept it!

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

추가 답변 (1개)

Lieke Numan
Lieke Numan 2019년 3월 15일
I want to color the space between y=60 and y=100
datetime1=18-Aug-2017 22:56:00
datetime2=18-Aug-2017 23:56:00
This is what I wanted to do:
patch([datetime1 datetime2 datetime2 datetime1],[50 50 100 100],'red')
It also doesn't work when I use datenum(datetime1) within the patch function.

카테고리

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