首页 > 解决方案 > 在matlab中创建一个连续的日期字符串

问题描述

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

'20160801'
'20160802'
'20160803'
.
.
.
'20161031'

标签: matlab

解决方案


这应该可以正常工作:

% 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');

推荐阅读