How do you plot Matlab serial dates on a figure?

조회 수: 1 (최근 30일)
harsh
harsh 2012년 9월 2일
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
per isakson
per isakson 2012년 9월 2일
Did you read and understand the documentation on datetick?

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
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
harsh
harsh 2012년 9월 2일
Sweet! I used
plot(cDate, DeltaP);
datetick( 'x', 'mm/dd/yyyy');
I tried 'keeplimits' but it only gave me one date on the x-axis, without keep limit, it plots the whole graph, but the x-axis stretches from 1/1/2011 to 1/1/2013. How do I make the dates on the figures be from 8/31/2011 to 8/31/2012?
per isakson
per isakson 2012년 9월 3일
편집: per isakson 2012년 9월 3일
See answer above.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by