Re: [讨论] 读取excel内"时间"栏问题

楼主: celestialgod (天)   2016-06-15 11:56:59
※ 引述《sin55688 (交大鲁圣)》之铭言:
: 我有一笔Excel资料 纪录著时间
: 例如
: 2014/2/12 18:22
: 2013/10/13 12:44
: 2015/1/31 12:28
: 2014/7/11 19:09
: 2013/11/15 12:52
: 2014/4/25 13:04
: 利用读档指令:
: [NUMERIC,data,RAW]=xlsread('train.csv');
: 会自动变成
: '2014/2/12 下午 06:22:00'
: '2013/10/13 下午 12:44:00'
: '2015/1/31 下午 12:28:00'
: '2014/7/11 下午 07:09:00'
: '2013/11/15 下午 12:52:00'
: '2014/4/25 下午 01:04:00'
: 跑出中文来...,在Matlab中文字串处理让我有点崩溃XD
: 有没有让MATLAB 可以不要这么鸡婆转换的方法??
test.xlsx:
2014/2/12 18:22
2013/10/13 12:44
2015/1/31 12:28
2014/7/11 19:09
2013/11/15 12:52
2014/4/25 13:04
2013/10/13 00:44
main.m:
[~, dates] = xlsread('test.xlsx');
% '2014/2/12 下午 06:22:00'
% '2013/10/13 下午 12:44:00'
% '2015/1/31 下午 12:28:00'
% '2014/7/11 下午 07:09:00'
% '2013/11/15 下午 12:52:00'
% '2014/4/25 下午 01:04:00'
% '2013/10/13 上午 12:44:00'
dates = regexprep(dates, '下午\s*(\d{2}:\d{2}:\d{2})', '$1 PM');
dates = regexprep(dates, '上午\s*(\d{2}:\d{2}:\d{2})', '$1 AM');
datestr(dates)
% 12-Feb-2014 18:22:00
% 13-Oct-2013 12:44:00
% 31-Jan-2015 12:28:00
% 11-Jul-2014 19:09:00
% 15-Nov-2013 12:52:00
% 25-Apr-2014 13:04:00
% 13-Oct-2013 00:44:00
作者: name0625 (lawpy)   2016-06-15 13:14:00
c大一出手,就知有没有!
作者: sin55688 (单手挑藏獒)   2016-06-16 00:00:00
感谢帮忙。 话说00:00:00 时间还会被自动转成空白ˊˋ真是诡异@@

Links booklink

Contact Us: admin [ a t ] ucptt.com