split numbers into coloumns

Hello all
I have a raw of data with 16 digits like 0799569419940319, the last 8 digits are the year, the month and the day. How can I split the cells to extract the year and month and day?

4 件のコメント

Stephen23
Stephen23 2022 年 12 月 12 日
"I have a raw of data with 16 digits like 0799569419940319..."
What are you importing this data from? What data type does it have?
Please upload a sample file by clicking the paperclip button. Actual data is always more accurate than explanations of data.
John D'Errico
John D'Errico 2022 年 12 月 12 日
You don't say what the other digits represent. But if these "numbers" are always 16 digits, And the first digit can be a 9, then potentially you need to be careful.
format long
2^53-1
ans =
9.007199254740991e+15
Some of those numbers will overflow what can be stored in a double as an integer. If that is the case, then the least significant digit, representing the day may not be correctly returned.
The point is, you will most safely want to read those numbers in as text, and then use text processing tools to extract the year, month and day, as characters. Only then would you convert them to a numeric form.
Star Strider
Star Strider 2022 年 12 月 12 日
Consider:
n = 0799569419940319;
ns = num2str(n);
dn = ns(end-7:end) % Date Segment
dn = '19940319'
nn = ns(1:end-8) % Number Segment
nn = '7995694'
DT = datetime(dn, 'InputFormat','yyyyMMdd') % 'datetime' Vector
DT = datetime
19-Mar-1994
I hav no idea what the rest of these numbers are, so I cannot generalise this and so am not posting this as an Answer.
.
Jan
Jan 2022 年 12 月 12 日
The leading zero let me assume, that this is not a number, but a CHAR vector. But if it is really a number:
n = 0799569419940319;
day = rem(n, 100)
day = 19
month = rem(floor(n / 100), 100)
month = 3
year = rem(floor(n / 10000), 10000)
year = 1994

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2022 年 12 月 12 日

コメント済み:

Jan
2022 年 12 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by