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

4 vues (au cours des 30 derniers jours)
Christopher McCausland
Christopher McCausland le 1 Juin 2022
Commenté : Voss le 4 Juin 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'

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by