Does pcolor support datetime?

10 ビュー (過去 30 日間)
Kevin J. Delaney
Kevin J. Delaney 2017 年 9 月 7 日
回答済み: Pooja Lalan 2017 年 9 月 13 日
Does pcolor support datetime axes? When I call pcolor with a datetime vector it produces the error "Data inputs must be real."

回答 (1 件)

Pooja Lalan
Pooja Lalan 2017 年 9 月 13 日
In my understanding, you would like to have date formatted tick labels for axes when using 'pcolor'. You cannot directly provide 'pcolor' with datetime vectors as of now.
However, there is a way to use the ' datenum ' and ' datetick ' functions to get datetime axes tick labels as illustrated in the example below:
%Creating two example vectors of datetimes, tx and ty
t1 = datetime(2017,9,2,0,0,0);
t2 = datetime(2017,9,30,0,0,0);
tx = t1:5:t2;
ty = tx + day(15);
%Creating an example C matrix for pcolor plot
C = magic(length(tx));
% Using datenum to convert to real numbers for plotting and dateticks for
% date labelling. You can play around with datetick options to suit your needs
pcolor(datenum(tx), datenum(ty), C);
datetick('y', 'dd-mm-yy', 'keepticks');
datetick('x', 'dd-mm-yy', 'keepticks');
I hope this accomplishes what you would like to do.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by