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

3 visualizaciones (últimos 30 días)
Christopher McCausland
Christopher McCausland el 1 de Jun. de 2022
Comentada: Voss el 4 de Jun. de 2022
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'

Respuesta aceptada

Voss
Voss el 1 de Jun. de 2022
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 comentarios
Christopher McCausland
Christopher McCausland el 4 de Jun. de 2022
That makes sense, I can't believe I didnt see it!
Thank you!
Christopher
Voss
Voss el 4 de Jun. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by