MATLAB: I want to split cell vector

dataMATLABmatrixvector

Hi everyone,
I have one cell vector with the date in this format {YY-MM-DD}, I would like to obtain three different vectors that contain 'YY', 'MM', 'DD'. I tried to convert this in str and using strsplit command but it doesn't work. Is there someone that can help me?? Thanks.
date =
1472×1 cell array
{'1985-01-01'}
{'1985-01-01'}
{'1985-01-01'}
{'1985-01-01'}
{'1985-01-02'}
{'1985-01-02'}
{'1985-01-02'}
{'1985-01-02'}
{'1985-01-03'}
{'1985-01-03'}

Best Answer

Using datetime:
>> DT = datetime(date,'InputFormat','yyyy-MM-dd');
>> DT.Year
ans =
1985
1985
1985
1985
1985
1985
1985
1985
1985
1985
>> DT.Month
ans =
1
1
1
1
1
1
1
1
1
1
>> DT.Day
ans =
1
1
1
1
2
2
2
2
3
3
Or using regexp:
>> tkn = regexp(date,'^(\d+)-(\d+)-(\d+)$','tokens','once');
>> tkn = vertcat(tkn{:});
>> Y = tkn(:,1)
Y =
'1985'
'1985'
'1985'
'1985'
'1985'
'1985'
'1985'
'1985'
'1985'
'1985'
>> M = tkn(:,2)
M =
'01'
'01'
'01'
'01'
'01'
'01'
'01'
'01'
'01'
'01'
>> D = tkn(:,3)
D =
'01'
'01'
'01'
'01'
'02'
'02'
'02'
'02'
'03'
'03'