MATLAB: How to split a number in a vector into smaller components

delimiterloopvector

Hi,
I have a larger vector (1460 elements) of patent dates. It looks something like this (I'll only provide the first few elements to be concise):
patentgrantdate = [ 20000719; 20021112; 20030114; 20040601; 20040601; …];
I'd like to split it into a matrix with the same number of rows, but have a column for year, month and day, as follows:
patentgrantdatesplit =
[ 2000 07 19;
2002 11 12;
2003 01 14;
2004 06 01;
2004 06 01;
…];
It's probably going to have to use a loop since I have so many entries, but I'm not sure how to simultaneously reference elements in my vector and individual characters in those elements. Any help would be appreciated!

Best Answer

y = floor(patentgrantdate/10000);
m = floor((patentgrantdate-y*10000)/100);
d = patentgrantdate-y*10000-m*100;
patentgrantdatesplit = [y m d];