How can I split a number in a vector into smaller components?

2 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

the cyclist
the cyclist el 16 de Jul. de 2018
y = floor(patentgrantdate/10000);
m = floor((patentgrantdate-y*10000)/100);
d = patentgrantdate-y*10000-m*100;
patentgrantdatesplit = [y m d];

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by