How can I split a number in a vector into smaller components?
2 views (last 30 days)
Show older comments
Zachary George Batzing Westman
on 16 Jul 2018
Answered: the cyclist
on 16 Jul 2018
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!
0 Comments
Accepted Answer
the cyclist
on 16 Jul 2018
y = floor(patentgrantdate/10000);
m = floor((patentgrantdate-y*10000)/100);
d = patentgrantdate-y*10000-m*100;
patentgrantdatesplit = [y m d];
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!