1.创建一组时间序列
clear
clc
close all
% 创建起始时间和结束时间
startDateTime = datetime('2024-01-01 00:00:00', 'Format', 'yyyy-MM-dd HH:mm:ss');
endDateTime = datetime('2024-01-01 23:59:59', 'Format', 'yyyy-MM-dd HH:mm:ss');
% 创建时间点序列,每隔一分钟
timePoints = startDateTime:minutes(1):endDateTime;
timePoints=timePoints';
% 找到特定时间点的行
targetDateTime = datetime('2024-01-01 00:37:00', 'Format', 'yyyy-MM-dd HH:mm:ss');
rowIndex = find(timePoints == targetDateTime)
% 显示结果
disp(timePoints);
2.时间序列和字符串转化
clear
clc
close all
% 原始日期时间字符串
datetimeStr = '2024-04-04 11:32:20';
% 将字符串转换为 datetime 类型
dt = datetime(datetimeStr, 'InputFormat', 'yyyy-MM-dd HH:mm:ss');
% 将 datetime 类型转换为指定格式的字符串
cc = datestr(dt, 'yyyymmddHHMMss');
disp(cc);
本文介绍了如何在MATLAB中创建时间序列,包括定义起始和结束时间,以及如何查找特定时间点的行。同时展示了字符串到datetime类型的转换和datetime类型的格式化输出过程。
1643

被折叠的 条评论
为什么被折叠?



