reshaping 2 vectors of dates

Hi everyone
I have the following cell vector of dates
D={'September-October 2000' ...
'November-December 2000' ...
'January-Febraury 2001'...
'March-April 2001'...
'May-June 2001'};
Is there any way to change it to
D={'SO 2000' ...
'ND 2000' ...
'JF 2001'...
'MA 2001'...
'MJ 2001'};
Where as you can see I use only the first letter from each pair of months
The second cell vector of dates is the following
DD={ '4 Weeks Ending 24.09.00'...
'4 Weeks Ending 22.10.00'...
'4 Weeks Ending 19.11.00'...
'4 Weeks Ending 17.12.00'...
'4 Weeks Ending 14.01.01'...
'4 Weeks Ending 11.02.01'};
Is there a way to change it to
DD={ '4W240900'...
'4W221000'...
'4W191100'...
'4W171200'...
'4W140101'...
'4W110201'};
Where as you can see I merge number 4 with the first letter of the word ‘Weaks’ and the dates from which I omit the dot
cheers

5 Comments

Is the difference between "Weeks" and "Weaks" intended? Why does '4W19.11.00' still contains dots, while the other string don't?
Ooops! Sorry I meant weeks and '4W191100'
Then, antonet, it would be a good idea to edit your question now to avoid confusing the readers.
antonet
antonet on 9 Jul 2012
Edited: antonet on 9 Jul 2012
Ok! now. thank you
could anyone help? Thanks alot

Sign in to comment.

 Accepted Answer

Andrei Bobrov
Andrei Bobrov on 10 Jul 2012
Edited: Andrei Bobrov on 10 Jul 2012
variant use within regexprep
D = regexprep(D,'[a-z\-]','');
DD = regexprep(DD,'[ .a-zE]','');

5 Comments

antonet
antonet on 10 Jul 2012
Edited: antonet on 10 Jul 2012
for the first case I did
C2 = cellfun(@(x)[{x(1,[1 3])} {x([16 17 19 20 22 23])}],D,'uni',false);
C2 = vertcat(C2{:});
jji=cellfun(@(x) [x(1:2) '/' x(3:4) '/' x(5:6)], C2(:,2), 'UniformOutput', false);
Thanks Andrei. with
DD = regexprep(DD,'[ .a-zE]','');
I get
'S-O2000'
Is it possible to have
SO 2000
Hi Antonet!
D={'September-October 2000' ...
'November-December 2000' ...
'January-Febraury 2001'...
'March-April 2001'...
'May-June 2001'};
D = regexprep(D,'[a-z\-]','');
DD={ '4 Weeks Ending 24.09.00'...
'4 Weeks Ending 22.10.00'...
'4 Weeks Ending 19.11.00'...
'4 Weeks Ending 17.12.00'...
'4 Weeks Ending 14.01.01'...
'4 Weeks Ending 11.02.01'};
DD = regexprep(DD,'[ .a-zE]','');
wOw. YOU ARE THE BEST!
antonet
antonet on 10 Jul 2012
Edited: antonet on 10 Jul 2012
just a small question. In case some dates are empty how can i modify these codes?
FOr instance
D={' ' ...
'November-December 2000' ...
'January-Febraury 2001'...
'March-April 2001'...
'May-June 2001'};
DD={' '...
'4 Weeks Ending 22.10.00'...
'4 Weeks Ending 19.11.00'...
'4 Weeks Ending 17.12.00'...
'4 Weeks Ending 14.01.01'...
'4 Weeks Ending 11.02.01'};

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!