Timetables inside table are not updating correctly

10 ビュー (過去 30 日間)
pcm314
pcm314 2021 年 6 月 14 日
編集済み: pcm314 2021 年 6 月 16 日
Hello,
I'm trying to fill a table with timetables and scalar values (for Diagnostic feature Designer APP input) and I'm having some troubles defining the table.
I 'm using the following to create the table; where MatStruct is a structure (output of dir()) that contains the directories and filenames of the .mat files that I want to load and read.
sz = [length(MatStruct),4];
varTypes = {'timetable','timetable','timetable','double'};
DataTable = table('size',sz,'VariableNames',{'channel1','channel2','channel3','ConditionVar'},'VariableTypes',varTypes);
At this point the table is created properly, so I start to load and read the actual data onto the table:
for i=1:length(MatStruct)
load(fullfile(MatStruct(i).folder,MatStruct(i).name))
dt = diff(TIME);
dt = dt(1);
ch1 = array2timetable(channel1,'SampleRate',1/dt);
ch2 = array2timetable(channel2,'SampleRate',1/dt);
ch3 = array2timetable(channel3,'SampleRate',1/dt);
DataTable(i,1) = {ch1};
DataTable(i,2) = {ch2};
DataTable(i,3) = {ch3};
DataTable(i,4) = {ConditionVar};
end
For some reason, the first 3 columns (timetable columns) of the table are not being updated with ch1, ch2 and ch3; they keep the inital 1x0 timetable that appeared once the table was created. The fourth column scalar values, 'ConditionVar', is working fine (code not shown).
ans =
table
channel1
_______________
[1×0 timetable]
Whereas, if create the table as
DataTable = table()
The table ends up with the correct values, but I can't name table's variables so it is a bit messy when using the APP.
ans =
table
Var1
__________________
{5383×1 timetable}
I would like to understand why my created timetables are not being updated onto the table.
Thank you very much,
  4 件のコメント
pcm314
pcm314 2021 年 6 月 15 日
Hello @dpb,
The reason of putting timetables (followed by a condition varible which can be a scalar or a categorical variable) inside a table is because, as far as I know, is te best way to input data to the Diagnostic Feature Designer APP of the Predictive Maintenace toolbox.
Here you can see how input data should look like:
Thank you very much
dpb
dpb 2021 年 6 月 15 日
With R2020b here I can't find any syntax that will let me enter a timetable of multiple rows into a table as a collapsed variable with only one auxiliary variable the way that example shows.
Which release do you have/does the sample app require? I didn't go searching, not having that app, but is there another page that goes with it that shows how that sample dataset was created?
Whatever I do, I run into the problem
>> T=table('Size',[1,2],'VariableTypes',{'timetable','double'})
T =
1×2 table
Var1 Var2
_______________ ____
[1×0 timetable] 0
>> T(1,1)=tmp
To assign to or create a variable in a table, the number of rows must match the height of the table.
>> whos tmp
Name Size Bytes Class Attributes
tmp 8x1 1118 timetable
>> T=table(tmp,0,'Size',[1,2],'VariableTypes',{'timetable','double'})
Error using table (line 233)
All table variables must have the same number of rows.
>>
It will create a composite datatable type, but can't store a real timetable into it; if embed the timetable as above it is contained in the table as a variable but still of the same height.
I don't see how to build the table they show, sorry...

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 6 月 15 日
I think the issue is that you are treating tables like cells. In a cell, each can be a variable. However, in a table, an entire column represents a variable. You cannot, therefore, assign a table to a single element (row) of a column. It must be assigned to the entire column.
dt = 0.05;
channel1 = rand(3,2);
channel2 = rand(3,2);
channel3 = rand(3,2);
ch1 = array2timetable(channel1,'SampleRate',1/dt);
ch2 = array2timetable(channel2,'SampleRate',1/dt);
ch3 = array2timetable(channel3,'SampleRate',1/dt);
% Notice the variable names, ch1-3, across the top of the table
% The timetable variable names are displayed under the table variable names
% The timetable values are shown in their corresponding columns under ch1,
% ch2, and ch3
TT = table(ch1,ch2,ch3)
TT = 3×3 table
ch1 ch2 ch3 Time channel11 channel12 Time channel21 channel22 Time channel31 channel32 __________________________________ __________________________________ __________________________________ 0 sec 0.26206 0.96846 0 sec 0.049802 0.6536 0 sec 0.1514 0.30417 0.05 sec 0.29422 0.23072 0.05 sec 0.70208 0.07587 0.05 sec 0.81389 0.17342 0.1 sec 0.5714 0.26852 0.1 sec 0.012769 0.16812 0.1 sec 0.011715 0.36192
I think you need to rethink your approach for storing the data.
  13 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 6 月 15 日
I agree. I cannot think of a scenario where it would work. In the feedback, I have also suggested they consider not allowing these data types for VarType.
dpb
dpb 2021 年 6 月 15 日
Feedback appreciated, muchly...inquiring minds and all that... :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeManage System Data についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by