Year in column 1 and month in column 2

1 view (last 30 days)
Sahil Jain
Sahil Jain on 18 Jan 2019
Answered: 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??

Answers (2)

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

madhan ravi
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(:)]

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!