making `errorbar` work with `datetime`

3 ビュー (過去 30 日間)
Pankaj
Pankaj 2019 年 8 月 22 日
回答済み: Lei Hou 2019 年 8 月 27 日
I would like to plot errorbar with datetime on x-axis
x = datetime(['21-Aug-2019'; '22-Aug-2019'; '23-Aug-2019']);
y = [100; 110; 130];
figure
plot(x,y, '.')
hold on
errorbar(x, y, 20)
The final error produces this error
Error using errorbar (line 76)
Input arguments must be numeric or objects which can be converted to double.
Even the following produces error
errorbar(datenum(x), y, 20*ones(size(y)))
I am using R2016b

採用された回答

Sai Sri Pathuri
Sai Sri Pathuri 2019 年 8 月 26 日
The errorbar function does not accept datetime object as an input argument. Try to use datenum function to declare the input and note that the third argument must have same size as y.
When you are using the following function,
errorbar(datenum(x),y,20*ones(size(y)));
Try to use the datenum(x) instead of x in plot to avoid the error.
plot(datenum(x), y,'.');

その他の回答 (1 件)

Lei Hou
Lei Hou 2019 年 8 月 27 日
Sai is correct that errorbar doesn't yet support datetimes. I've made an enhancement request, and hopefully errorbar will be updated in a not-too-distant upcoming release.

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by