Use MATLAB to create Time Dimension Data

Source: Internet
Author: User

% Generate date_data
Date = datestr (datenum (): datenum (), 29); % using 29 --- ISO define
Vector = datevec (date );
Vector = vector );
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} = 'cmdl ';
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} = 'decimal ';
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 (, 1): datenum (,): datenum (, 31 ));
Vector = datevec (date );
Vector = vector );
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} = 'cmdl ';
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} = 'decimal ';
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 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.