代码之家  ›  专栏  ›  技术社区  ›  bahram khazaei

在matlab中创建连续的日期字符串

  •  0
  • bahram khazaei  · 技术社区  · 7 年前

    如何在matlab中创建这样的连续日期字符串:

    '20160801'
    '20160802'
    '20160803'
    .
    .
    .
    '20161031'
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Tommaso Belluzzo    7 年前

    这应该可以正常工作:

    % Define the starting and ending dates from literal representations...
    date_start = datetime('20160801','InputFormat','yyyyMMdd');
    date_end = datetime('20161031','InputFormat','yyyyMMdd');
    
    % Create a range of dates using the colon operator...
    date_range = (date_start:date_end).';
    
    % Convert the dates back to the desired literal format...
    date_text = datestr(date_range,'yyyyMMdd');