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 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