Home > Archive > Matlab > April 2005 > importing dates from excel
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
importing dates from excel
|
|
| Emir Emiray 2005-04-22, 4:04 pm |
| Hello,
I have dates in an excel file
date
22.05.05
23.05.05
24.05.05
..
..
..
I would like to import them to matlab, but I can't.
The way I go around is:
1. Format these dates as numbers in excel
2. import them to matlab
3. use x2mdate to transform these numbers to matlab date format
4. use datestr function to see actual dates.
But I would like to learn a better way. Can anyone help?
| |
| Michael Robbins 2005-04-22, 9:00 pm |
| Emir Emiray wrote:
>
>
> Hello,
>
> I have dates in an excel file
>
> date
> 22.05.05
> 23.05.05
> 24.05.05
> .
> .
> .
> I would like to import them to matlab, but I can't.
>
> The way I go around is:
> 1. Format these dates as numbers in excel
> 2. import them to matlab
> 3. use x2mdate to transform these numbers to matlab date format
> 4. use datestr function to see actual dates.
>
> But I would like to learn a better way. Can anyone help?
>
FID=fopen('yourfile.txt','r');
dts=sscanf(FID,'%d.%d.%d');
flcose(FID);
DTS = datestr(datenum(fliplr( ...
reshape(dts,length(dts)/3,3)'+ ...
(repmat([0 0 2000],length(dts)/3,1)))))
ans =
22-May-2005
23-May-2005
24-May-2005
| |
| Michael Robbins 2005-04-22, 9:00 pm |
| > dts=sscanf(FID,'%d.%d.%d');
That should have read
dts=fscanf(FID,'%d.%d.%d');
But the example I gave was for a text file. For an excel file
change:
[color=darkred]
> FID=fopen('yourfile.txt','r');
> dts=sscanf(FID,'%d.%d.%d');
> flcose(FID);
XLdts = xlsread('yourfile.xls');
dts=sscanf(XLdts,'%d.%d.%d');
|
|
|
|
|