1

I have a cell array of strings the first few elements of which look like:

'140322P00024000'
'140324PR0025000'
'140325P00Q26000'

where '140322' refers to 2014-03-22 (22nd march, 2014). I want to obtain the following array from the above:

735680
735682
735683

Please note in the given array only the first 6 letters are consistent and they refer to date.

2 Answers 2

2

The first six characters can be converted with datenum directly using the format 'yymmdd':

>> d = datenum('140322','yymmdd')
d =
      735680
>> datestr(d)
ans =
22-Mar-2014

Do them all with cellfun:

>> cellfun(@(x)datenum(x(1:6),'yymmdd'),C)
ans =
      735680
      735682
      735683
Sign up to request clarification or add additional context in comments.

Comments

0
DateString = '19-May-2001';
formatIn = 'dd-mmm-yyyy';
datenum(DateString,formatIn)

Taken from:

http://www.mathworks.com/help/matlab/ref/datenum.html

Converting to the 'DD-MM-YYYY' string should be straightforward:

currentLine = cellArray{y,x};
DateString = [currentLine[3:4] '-' currentLine[5:6] '-20' currentLine[1:2]];

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.