From: Josh Jones on
I am relatively new to MATLAB, and just can't figure this one out although it is probably easy. I have a data set in which the date is of the form yyyymmdd, and use the following to convert it into a MATLAB date:
date = datestr(datenum(sprintf('%d',day),'yyyymmdd'),'mm-dd-yyyy');
This only returns a date for the first row of the data and I can't figure out how to get it to return a column of dates for the variable 'date'. Thanks for any help!
Josh
From: Oleg Komarov on
"Josh Jones" <joshua.jones(a)gi.alaska.edu> wrote in message <i0dkaj$ggl$1(a)fred.mathworks.com>...
> I am relatively new to MATLAB, and just can't figure this one out although it is probably easy. I have a data set in which the date is of the form yyyymmdd, and use the following to convert it into a MATLAB date:
> date = datestr(datenum(sprintf('%d',day),'yyyymmdd'),'mm-dd-yyyy');
> This only returns a date for the first row of the data and I can't figure out how to get it to return a column of dates for the variable 'date'. Thanks for any help!
> Josh

if day = {'20100423';'20100424'}

date = datestr(datenum(day,'yyyymmdd'),'mm-dd-yyyy');
%Or
cellfun(@(x) sprintf('%s-%s-%s',x(7:8),x(5:6),x(1:4)),day,'un',0)

Oleg