how to join the values of different cells in different columns in one cell ?

1 回表示 (過去 30 日間)
MA
MA 2021 年 9 月 20 日
コメント済み: Walter Roberson 2021 年 9 月 20 日
Is there a way that might allow me to combine several columns of a table in one column and put the values of their cells together in one cell. for example I have the table shown below, the first five columns are for the year, month, day, hour, minute. Would I be able to join them all together in one column such that the values would have such representation: 19961211720 where 1996 is the year, 12 is the month, 1 is the day , 17 is the hour and 20 is the minute.
anyone can help?

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 20 日
T.Date = datetime(T.Year, T.Month, T.Day, T.Hour, T.Min, 0, 'Format', 'uuuuMMddhhmm');
Note: I did not use the format you asked for. You asked for a single digit for the day, but I used two digits for the day. Even in the case where you might happen to know that only a single digit will ever be used, using a single digit is non-standard and makes things harder to understand all around.
  3 件のコメント
MA
MA 2021 年 9 月 20 日
Is there any modification I can add to keep the hours in 24hr format not 12hr format? (i.e. to have for the HOUR value 17 instead of 05).
Walter Roberson
Walter Roberson 2021 年 9 月 20 日
T.Date = datetime(T.Year, T.Month, T.Day, T.Hour, T.Min, 0, 'Format', 'uuuuMMddHHmm');

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

その他の回答 (1 件)

Simon Chan
Simon Chan 2021 年 9 月 20 日
Suppose you read the file using function readtable and the name of the table is T, then variable C in the following will give you the required format.
format longG
Ncol = 5;
A=table2array(T(:,1:Ncol));
B=compose(repmat('%d',1,Ncol),A);
C=str2double(B)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by