From: Sal on
Hello,
I am trying to read date values from some array but of little/no avail. (this may seem trivial, but i just started using matlab 2 weeks ago)

I have a huge array called 'ddmmyy' (210345x1) which contains different dates stored as double integers.
e.g. ddmmyy(1) = 070403 which is 7th April 2003.

My objective (for each date stored in 'ddmmyy') is to calculate the number of hours since 1st January 1900.

My idea was to 1st convert this date into a string format, and then convert the string into a serial date number using N = datenum(S, F, P), with P being 01 January 1900.
This would have given me the number of days since 01/01/1900 and I would simply multiply it by 24 to get the hours.

1. However, i get really weird dates whenever i try to convert any of the arrays into strings. e.g. S = datestr(ddmmyy(1)) gives me S = 02-Oct-0192, which doesn't makes sense.

2. I tried writing the array to an spreadsheet file and changing the format of the data. However, there were several issues
A. Spreadsheet can take a maximum of 65536 rows, so 210345/65536 = 3.3.., which means at best, I would have to have the array written to excel file in increments, at least 4 times.

B. Some of the date values which were stored as 6 figures in the original array, (e.g. ddmmyy(10) = 160403, 16th April 2003) were stored in scientific form on the spreadsheet, and seemed to have lost the last number (i.e. ddmmyy(10) came out as 160400). I was wondering if it had anything to do with fact that I am on LINUX machine, that uses openoffice Calc, which is not exactly MS excel.

3. Right now, I'm just confused how to proceed; The array is quite large but it has been loaded from text file, using load import wizard. Also, i need to analyse all of the dates stored in it. It is the formatting of the stored sates values, that I am having trouble dealing with. Also, now I am beginning to have doubts whether the pivot method would work at all.

Any advice/help would be much appreciated. I'm really lost
From: Walter Roberson on
Sal wrote:

> I have a huge array called 'ddmmyy' (210345x1) which contains different
> dates stored as double integers. e.g. ddmmyy(1) = 070403 which is 7th
> April 2003.
>
> My objective (for each date stored in 'ddmmyy') is to calculate the
> number of hours since 1st January 1900.
>
> My idea was to 1st convert this date into a string format, and then
> convert the string into a serial date number using N = datenum(S, F, P),
> with P being 01 January 1900.
> This would have given me the number of days since 01/01/1900 and I would
> simply multiply it by 24 to get the hours.

You use an example in which 03 is intended to designate the year 2003, but you
want to use a pivot year of 1900, which means that all 2 digit years would be
added to 1900, and thus 03 should represent 1903. You have an incompatibility
in your specifications.

Y = mod(ddmmyy,100);
beforePivot = Y < 20;
Y(beforePivot) = Y(beforePivot) + 100;
M = mod(fix(ddmmyy ./ 100), 100);
D = fix(ddmmyy ./ 10000);

Now put together Y M D and some constants to create a datevec array, and
datenum() that datevec array to get the days since 1900. Multiply by 24 to get
hours since 1900.
 | 
Pages: 1
Prev: Reassign values
Next: Reassign values