How to patch upperbound and lowerbound

6 vues (au cours des 30 derniers jours)
alpedhuez
alpedhuez le 23 Août 2021
Commenté : Star Strider le 23 Août 2021
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 commentaire
alpedhuez
alpedhuez le 23 Août 2021
Modifié(e) : alpedhuez le 23 Août 2021
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?

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 23 Août 2021
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 commentaires
alpedhuez
alpedhuez le 23 Août 2021
use of flipud is the key. Thank you.
Star Strider
Star Strider le 23 Août 2021
As always, my pleasure!
.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by