MATLAB Answers

0

Year in column 1 and month in column 2

Asked by Sahil Jain on 18 Jan 2019
Latest activity Answered by madhan ravi
on 18 Jan 2019
I want to create a time series with year in column 1 (1901-2017) and month in column 2 (1-12 repeated with changing year)
1901 1
1901 2
1901 3
.
.
.
.
2017 12
How can I do so??

  0 Comments

Sign in to comment.

2 Answers

Answer by Stephan
on 18 Jan 2019

col1 = repelem(1901:2017,12)';
col2 = repmat(1:12,1,numel(col1)/12)';
result = [col1 col2]

  0 Comments

Sign in to comment.


Answer by madhan ravi
on 18 Jan 2019

Perhaps?
t=datetime(2017,01,01):calmonths(1):datetime(2017,12,31);
[year,month,~]=ymd(t);
Result=[year(:) month(:)]

  0 Comments

Sign in to comment.