Error in Joining multiple date time duration id date is in cell Array

조회 수: 2 (최근 30일)
I am working on time series data. I am joining multiple time duration data . I need help, If duration is in cell array then I am unable to join the time series .
I am getting the following error
Error in matlab.internal.tabular.private.numArgumentsFromSubscriptRecurser (line
7)
n = numArgumentsFromSubscript(a, s, ctxt);
Error in tabular/numArgumentsFromSubscript (line 97)
sz =
matlab.internal.tabular.private.numArgumentsFromSubscriptRecurser(x,s,context);
Error in get_fieldnames (line 33)
structtable.Date = duration(structtable.Date.Hour,
structtable.Date.Minute, structtable.Date.Second); %extract h/m/s
and make that a duration.
Error in MainFcn (line 22)
[joinedtimetable] = get_fieldnames(Content);
I have added work bench. Please find the attachment. Please provide the correct file path.
  댓글 수: 3
Guillaume
Guillaume 2020년 1월 8일
What is the class and size of
structtable
structtable.Date
when the error occurs?
Completely unrelated and very minor but why the brackets around joinedtimetable in
[joinedtimetable] = get_fieldnames(Content);
They don't do any harm but are completely unnecessary. After all, you don't have brackets around errorMessage in
errorMessage = sprintf('Error: file not found:\n\n%s', fullFileName);
so why there?
Life is Wonderful
Life is Wonderful 2020년 1월 8일
편집: Life is Wonderful 2020년 1월 8일
Hi Adam ,
Once you extract the Issue_vmec.zip,
Please proivde the code we can execute to recreate the problem
Run file : MainFcn.m
Please add path manually from your PC [your *.zip file extract location]
Input filename is embedded in the *.zip itself. You should be able run the code outofbox.
Note - Error is observed when Test2 & Test3 is executed. Test1 is good case ( sample example)
Hi Guillaume
Question - when the error occurs?
class(structtable) is 'table'
class(structtable.Date) is 'Unknown'. We get the error for line
Error in get_fieldnames (line 33)
structtable.Date = duration(structtable.Date.Hour, structtable.Date.Minute, structtable.Date.Second); %extract h/m/s and make that a duration.
Sure, I will adapt the code as per your inputs.
Thank you very much!!

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 1월 8일
편집: Adam Danz 2020년 1월 8일
In Test2, the table is not being read in correctly. The image below is the result of line 36 in get_vmlog.m. As you can see, the datetime values are cell arrays of strings.
If you look at the content of vmlogLATEST, it's qualitatively different from uiLATEST which is read in correctly. I guess this is why you have two different functions to read in the data.
Sample of uiLATEST
Sample of vmlogLATEST
So, you'll need to adapt get_vmlog() to use similar logic as you're using in get_ui() to read the datetime values.
Create vector of datetime from cell array of string values
To convert the Date values shown in the first screen shot image above to datetime values, add these two lines of code to your get_vmlog.m file after readtable().
I'm guessing you want to convert {'[0616/104015]'} to 10:40:15 following the logic of your previous questions.
Content.vmlog = readtable(filename, opts);
% convert cell array of time strings to datetime
timeStr = regexp(Content.vmlog.Date,'\d{6}','match');
Content.vmlog.Date = datetime([timeStr{:}],'InputFormat','HHmmss','Format','HH:mm:ss')';
  댓글 수: 6
Adam Danz
Adam Danz 2020년 1월 9일
Glad I could help! But for your next question, I'm affraid I know nothing about LAN Medium Access Control.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sylvain Lacaze
Sylvain Lacaze 2020년 1월 8일
Hi Matlab,
You're overriding yourself:
structtable.Date = duration(structtable.Date.Hour, structtable.Date.Minute, structtable.Date.Second);
In the first iteration of the loop, structtable.Date is a datetime array, but you then step on it, to make it a duration. In the second iteration of the loop, structtable.Date.Hour doesn't exist (Hour is not a property of a duration object).
Did you mean:
structtable.SomeotherVariableNameLikeDuration = duration(structtable.Date.Hour, structtable.Date.Minute, structtable.Date.Second);
HTH,
Sylvain

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by