How to patch upperbound and lowerbound

6 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2021 年 8 月 23 日
コメント済み: Star Strider 2021 年 8 月 23 日
I read about patch to fill in the confidence interval
But I am not yet sure of how it works. (Partly due to the fact that https://www.mathworks.com/help/matlab/ref/patch.html only has graphic examples.)
Suppose I have
plot(T.date,upperbound)
hold on
plot(T.date,lowerbound)
Then how can one fill in upperbound and lowerbound?
  1 件のコメント
alpedhuez
alpedhuez 2021 年 8 月 23 日
編集済み: alpedhuez 2021 年 8 月 23 日
I have tried https://www.mathworks.com/matlabcentral/answers/180829-shade-area-between-graphs but does not seem to work. Maybe it is because x axis is a datetimie variable?

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2021 年 8 月 23 日
Try something like this —
T = table(datetime('now')+days(1:14).', rand(14,1), rand (14,1)+1, 'VariableNames',{'date','lowerbound','upperbound'})
T = 14×3 table
date lowerbound upperbound ____________________ __________ __________ 24-Aug-2021 15:54:18 0.3007 1.7723 25-Aug-2021 15:54:18 0.68026 1.703 26-Aug-2021 15:54:18 0.4398 1.6127 27-Aug-2021 15:54:18 0.62549 1.237 28-Aug-2021 15:54:18 0.44381 1.6517 29-Aug-2021 15:54:18 0.71737 1.3115 30-Aug-2021 15:54:18 0.41553 1.1505 31-Aug-2021 15:54:18 0.56936 1.405 01-Sep-2021 15:54:18 0.064302 1.329 02-Sep-2021 15:54:18 0.85725 1.5955 03-Sep-2021 15:54:18 0.15449 1.7525 04-Sep-2021 15:54:18 0.91195 1.8573 05-Sep-2021 15:54:18 0.10671 1.4731 06-Sep-2021 15:54:18 0.41436 1.6558
figure
patch([T.date; flipud(T.date)], [T.lowerbound; flipud(T.upperbound)], 'r', 'FaceAlpha',0.5)
grid
The patch function until recently did not work with datetime arrays, so it was necessary to use fill instead, with the same syntax as demonstrated here.
.
  2 件のコメント
alpedhuez
alpedhuez 2021 年 8 月 23 日
use of flipud is the key. Thank you.
Star Strider
Star Strider 2021 年 8 月 23 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolygons についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by