How do you plot Matlab serial dates on a figure?
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to plot dates on a figure on the x-axis, and show actual dates versus Matlab serial date numbers (i.e. I want to plot 8/31/2011 vs. 735112 on the figure). How do you do that?
Here are my commands:
importfile('chk.xls');
cDate = Date;
cDate = x2mdate(cDate, 0);
str = datestr(cDate, 1);
cDt = cellstr( str )
I converted cDate to a cell array thinking it would have done the trick, but it didn't. I am now stuck with a cell vector of the same size as my variables from chk.xls, which are double vectors as the same size.
1 件のコメント
回答 (1 件)
per isakson
2012 年 9 月 2 日
編集済み: per isakson
2012 年 9 月 3 日
Did you read and understand the documentation on datetick?
You need to do something like
plot( cDate, data )
datetick( 'x', 'mm/dd/yyyy' )
where cDate is a Matlab serial date number
Did I completely misunderstand what you try to achieve? Maybe I did. Does this do it?
plot( cDate, cDate, 'd' )
datetick( 'y', 'mm/dd/yyyy', 'keeplimits' )
.
-- In response to comment 1 ---
By mistake, I wrote 'keeplimits' above instead of 'keepticks'. However, that revealed you did not read the documentation carefully enough. 'keepticks' makes sure that the ticks, which where assigned by plot, are kept. The problem is that the "datestrings" may be very wide and to compensate for that datatick might choose fewer ticks.
Default values don't always give a good result.
Low level stuff: The handle graphic object, axes, has properties, which controls many aspects of the diagram. With the property, XTick, you can control the positions and number of ticks and 'keepticks' makes sure that datetick doesn't tamper with your choice.
3 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!