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

2 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

the cyclist
the cyclist le 16 Juil 2018
y = floor(patentgrantdate/10000);
m = floor((patentgrantdate-y*10000)/100);
d = patentgrantdate-y*10000-m*100;
patentgrantdatesplit = [y m d];

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by