Importing a table as (:,1) timedate (:,2) categorical

4 ビュー (過去 30 日間)
Christopher McCausland
Christopher McCausland 2022 年 6 月 1 日
コメント済み: Voss 2022 年 6 月 4 日
Hi there,
I have used the import functionality in the past without issue, I am currently trying to import a .txt file which contains a column of timedate data and a column of categorical data (I will include some generated data below). I have tried to use the opts option however cannot get the format to work, I will include the script below;
opts = detectImportOptions('mytabledata.txt'); % Get opts to change
opts.VariableTypes{1} = 'datetime' % Change column 1
opts.VariableTypes{2} = 'categorical'; % Change column 2
opts.VariableOptions.DatetimeFormat ='HH:mm:ss.SS'; % Set weird TD format to match data
T = readtable('mytabledata.txt', opts); % apply new options
I get the following error for => opts.VariableOptions.DatetimeFormat ='HH:mm:ss.SS'; which I cannot work out.
Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list
assignment.
I don't really use the datetime variable enough to see what is happening and plan to change this to seconds anyways, I just need to make sure its importedd correctly first.
Kind regards,
Christopher
Table data looks something like this
'15:45:07.00' 'Stage 1'
'15:45:07.00' 'Stage 2'
'15:47:07.00' 'Stage 1'

採用された回答

Voss
Voss 2022 年 6 月 1 日
opts.VariableOptions is an array. You meant to set a property (DatetimeFormat) of the first element of the array but instead accidentally tried to set that property of all elements of the array.
% opts.VariableOptions.DatetimeFormat ='HH:mm:ss.SS'; % all elements
opts.VariableOptions(1).DatetimeFormat ='HH:mm:ss.SS'; % first element only
  2 件のコメント
Christopher McCausland
Christopher McCausland 2022 年 6 月 4 日
That makes sense, I can't believe I didnt see it!
Thank you!
Christopher
Voss
Voss 2022 年 6 月 4 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by