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

2 ビュー (過去 30 日間)
Zachary George Batzing Westman
Zachary George Batzing Westman 2018 年 7 月 16 日
回答済み: the cyclist 2018 年 7 月 16 日
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!

採用された回答

the cyclist
the cyclist 2018 年 7 月 16 日
y = floor(patentgrantdate/10000);
m = floor((patentgrantdate-y*10000)/100);
d = patentgrantdate-y*10000-m*100;
patentgrantdatesplit = [y m d];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by