フィルターのクリア

Formatted Datetime char values stored as numbers

1 回表示 (過去 30 日間)
Colin Edgar
Colin Edgar 2018 年 5 月 3 日
コメント済み: Colin Edgar 2018 年 5 月 3 日
t1=datetime(2012,1,1,0,0,0);
t2=datetime(2012,12,31,23,30,0);
TSarray=t1:minutes(30):t2; %this makes a timestamp array for one year in 30 min increments
TSarray.Format='yyyyMMddHHmm'; %displays the TS array the way I need it e.g. '201208161230' Aug 16 12:30
TSstr=cellstr(TSarray);
I don't see how to get the TSstr cell array (char), or the datetime output in general, to be converted into a number array (double) of the number as it appears in the format, and not the datenum value. There must be a way to control this with datenum. In other words I want a number array of the formatted date e.g. '201208161230'. Reason being that I wish to combine with other number arrays into output matrix.
outputdata = [TSstr,data1,data2,....];
201208161230 data1 data2 ...
201208161300 data1 data2 ...
201208161330 data1 data2 ...

採用された回答

Walter Roberson
Walter Roberson 2018 年 5 月 3 日
Tsout = year(TSarray)*10^8 + month(TSarray)*10^6 + day(TSarray)*10^4 + hour(TSarray)*10^2 + minute(TSarray);
(You can skip setting the Format before this.)
Or you could str2double(TSstr)
  3 件のコメント
Colin Edgar
Colin Edgar 2018 年 5 月 3 日
Now I need to get fprint to actually print the whole number :( I only get 201200000000 for whole year. How to get more that %.9g? I need 12 spaces.
Colin Edgar
Colin Edgar 2018 年 5 月 3 日
And the answer is..... %.12g. I failed to understand that while .5 means five, .12 means twelve

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by