MATLAB: Using Datenum to convert YYYY MM DD HH

datenumdatesembedded matlab functionmatrix arraymonthsyears

I have an 8219×6 matrix containing YYYY MM DD HH Wind_Speed Wind_Dir
I am trying to convert the first 4 columns using datenum using the code:
dNum = datenum([nineteen_49(:,1) nineteen_49(:,2) nineteen_49(:,3) nineteen_49(:,4) zeros(length(nineteen_49(:,4))) zeros(length(nineteen_49(:,4)))]);
But this isnt working as it is returning an 8219×16422 matrix instead of 8219×6. Not sure what the problem is?

Best Answer

dNum = datenum([nineteen_49(:,1:4) zeros(length(nineteen_49),2)]);
You missed the second argument to zeros in your augmentation and append two square matrices of 8219x8219 instead of two vectors of length 8219. I'm a little surprised datenum didn't error on the size of the vector 2nd dimension altho I suppose it took it as an extremely precise number of fractions of seconds after the minute, seconds and fractional seconds fields.