用MATLAB制造时间维度数据



%generate date_data
date=datestr(datenum(2010,1,1):datenum(2012,12,31),29);%using 29---iso define
vector=datevec(date);
vector=vector(:,1:3);
month=vector(:,2);
quarter=zeros(length(month),1);
for i=1:length(month)
    switch month(i)
        case {1,2,3}
            quarter(i)=1;
        case{4,5,6}
            quarter(i)=2;
        case{7,8,9}
            quarter(i)=3;
        case{10,11,12}
            quarter(i)=4;
    end
end
englishmonthname=cell(length(month),1);
for i=1:length(month)
    switch month(i)
        case 1
            englishmonthname{i}='January';
        case 2
            englishmonthname{i}='February';
        case 3
            englishmonthname{i}='March';
        case 4
            englishmonthname{i}='April';
        case 5
            englishmonthname{i}='May';
        case 6
            englishmonthname{i}='June';
        case 7
            englishmonthname{i}='July';
        case 8
            englishmonthname{i}='August';
        case 9
            englishmonthname{i}='September';
        case 10
            englishmonthname{i}='October';
        case 11
            englishmonthname{i}='November';
        case 12
            englishmonthname{i}='December';
    end
end
[w,d]=weekday(date);


vector=mat2cell(vector,ones(size(vector,1),1),ones(size(vector,2),1));
quarter=num2cell(quarter);
w=num2cell(w);
d=cellstr(d);
date=cellstr(date);
datekey=transpose(num2cell(1:length(date)));
output=cat(2,datekey,date,vector,quarter,englishmonthname,w,d);

 

 

 

 

 

 



%generate datetime_data
date=datestr(datenum(2010,1,1):datenum(0,0,0,1,0,0):datenum(2012,12,31));
vector=datevec(date);
vector=vector(:,1:4);
month=vector(:,2);
quarter=zeros(length(month),1);
for i=1:length(month)
    switch month(i)
        case {1,2,3}
            quarter(i)=1;
        case{4,5,6}
            quarter(i)=2;
        case{7,8,9}
            quarter(i)=3;
        case{10,11,12}
            quarter(i)=4;
    end
end
englishmonthname=cell(length(month),1);
for i=1:length(month)
    switch month(i)
        case 1
            englishmonthname{i}='January';
        case 2
            englishmonthname{i}='February';
        case 3
            englishmonthname{i}='March';
        case 4
            englishmonthname{i}='April';
        case 5
            englishmonthname{i}='May';
        case 6
            englishmonthname{i}='June';
        case 7
            englishmonthname{i}='July';
        case 8
            englishmonthname{i}='August';
        case 9
            englishmonthname{i}='September';
        case 10
            englishmonthname{i}='October';
        case 11
            englishmonthname{i}='November';
        case 12
            englishmonthname{i}='December';
    end
end
[w,d]=weekday(date);


vector=mat2cell(vector,ones(size(vector,1),1),ones(size(vector,2),1));
quarter=num2cell(quarter);
w=num2cell(w);
d=cellstr(d);
date=cellstr(datestr(date,'yyyy-mm-dd HH:MM:SS'));%or use datestr(date,31)
datekey=transpose(num2cell(1:length(date)));
output=cat(2,datekey,date,vector,quarter,englishmonthname,w,d);

save('input.mat','output');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值