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

2 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by