MATLAB Answers


Converting yymmddhhmm to mm/dd/yy hh:mm for Figure

Asked by Jessie
on 24 May 2013

I have a vector that has dates in the format of yymmddhhmm. When I create a time series contour plot, the dates show up as scientific numbers, but I want to display them as mm/dd/yy/ hh:mm.

  1 Comment

Please post an example. It is not clear if your input is the string '0305231950' or the number 305231950.


No products are associated with this question.

1 Answer

Answer by per isakson
on 24 May 2013
Edited by per isakson
on 24 May 2013


    str = '0305231950';
    sdn = datenum( str, 'yymmddHHMM' );
    datestr( sdn, 'mm/dd/yy/ HH:MM' )

and see plot data instead of number on the xaxis

And with a cell array of strings

    str = {'0305231950','0305231951','0305231952'};
    sdn = datenum( str, 'yymmddHHMM' );
    datestr( sdn, 'mm/dd/yy/ HH:MM' )

which outputs

    ans =
    05/23/03/ 19:50
    05/23/03/ 19:51
    05/23/03/ 19:52


Thank you, that did work! Do you know how I would do that for an entire vector of yymmddHHMM instead of a string?

"entire vector"(?) See above for a cell array of strings

Have you looked at the help file on datevec?

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!