MATLAB Answers

# create day month and year

13 views (last 30 days)
I want to create three tables in Matlab Year,Month and Day and then concatenate into one column so that
1970 1 1
1970 1 2
.
.
.
1970 12 1

#### 1 Comment

Stephen Cobeldick on 2 Sep 2016
Azzi Abdelmalek's answer is the fastest, neatest, and best solution to this question.

Sign in to comment.

### Accepted Answer

KSSV on 2 Sep 2016
clc; clear all
iwant = [ ];
for i = 1:12
d = calendar(1970,i)' ;
d(d==0) = [] ;
d = d(:) ;
y = repmat(1970,[length(d) 1]) ; % year
m = repmat(12,[length(d) 1]) ; % month
ymd = [y m d] ;
iwant = [iwant ; ymd] ;
end
there could be some other elegant way..

#### 1 Comment

Tanmoyee Bhattacharya on 2 Sep 2016
Thanks sir.It's helpful.

Sign in to comment.

### More Answers (1)

Azzi Abdelmalek on 2 Sep 2016
d1=datenum('01-01-1971','dd-mm-yyyy')
d2=datenum('31-12-1971','dd-mm-yyyy')
d=datevec(d1:d2)
d=d(:,1:3)

#### 2 Comments

KSSV on 2 Sep 2016
Good one...
Tanmoyee Bhattacharya on 28 Sep 2016
It's awesome

Sign in to comment.

Sign in to answer this question.