How do I use datetime on the x-axis of the errorplot.

5 ビュー (過去 30 日間)
Je
Je 2015 年 11 月 19 日
コメント済み: Star Strider 2015 年 11 月 20 日
So I have tried this with the normal plot function and then it works, but as I replace plot with errorbar it doesn't work anymore(of course I delete the extra information that is required for the error part of errorbar). This is the error I get when using datetime with errorbar: error using datetime/double (line 1468). Undefined function 'double' for input arguments of type 'datetime'.
Here is a bit of that code:
datums = ['25-09-2015'; '01-10-2015'; '06-10-2015'; '08-10-2015'; '15-10-2015'; '20-10-2015'; '21-10-2015'; '26-10-2015'; '27-10-2015';'28-10-2015'];
datums1 = datetime(datums,'Format','dd-MM-yyyy');
piek1 = [-4;-5;-6;-8;-1;-2;-4;-3;-4;-5];
error1 = [0.3960; 0.5300; 0.4830; 0.1800; 0.2330; 0.4210; 0.5910; 1.0170; 1.6480; 0.7370];
figure(1);
errorbar(datums1,piek1, error1) % gives error
% or plot(datums1,piek1) % this one does work correctly and as I want it to
Is there a way to plot datetime data on the x-axis of a errorbar plot (and still have it be in automatic mode)?

採用された回答

Star Strider
Star Strider 2015 年 11 月 19 日
Some plot functions don’t work and play well with datetime objects for some reason. A work-around is to use the datenum and datetick functions:
datums = ['25-09-2015'; '01-10-2015'; '06-10-2015'; '08-10-2015'; '15-10-2015'; '20-10-2015'; '21-10-2015'; '26-10-2015'; '27-10-2015';'28-10-2015'];
datnms = datenum(datums,'dd-mm-yyyy');
piek1 = [-4;-5;-6;-8;-1;-2;-4;-3;-4;-5];
error1 = [0.3960; 0.5300; 0.4830; 0.1800; 0.2330; 0.4210; 0.5910; 1.0170; 1.6480; 0.7370];
figure(1)
errorbar(datnms,piek1, error1) % gives error
datetick('x', 'dd-mm-yyyy')
You also had an error in your date format. The two-digit ‘month’ format is 'mm', minutes is 'MM'. (I fixed those here.)
  5 件のコメント
Je
Je 2015 年 11 月 20 日
adding this fixes the last issue: set(gca, 'XTickLabel', datestr(new_tks, 'dd-mm-yyyy'))
Star Strider
Star Strider 2015 年 11 月 20 日
My pleasure.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by