Can't assign VariableUnits to TimeTable
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to create a timetable for a motor simulation. I would like to keep track of the units of each variable.
Here is my code, a script in a file called CreateTT.m:
time.start = duration(0,0,0,0); %Start: 0m, 0s, 0ms
time.end = duration(0,1,0,0); %end: 1m
time.step = duration(0,0,0,1); %step: 1 ms
time.numsteps = (time.end - time.start) / time.step;
varNames = {'Angle','Angular Speed','Voltage','Current','Magnetic Field'};
varTypes = {'double','double','double','double','double'};
varUnits = {'degrees','deg/s','Volts','Amps','Tesla'};
data = timetable('Size', [time.numsteps, 5], 'VariableTypes', varTypes, 'TimeStep', time.step, 'VariableNames', varNames, 'VariableUnits', varUnits);
When I run it, I get the following error:
Error using timetable (line 335)
Invalid parameter name: VariableUnits.
Error in CreateTT (line 11)
data = timetable('Size', [time.numsteps, 5], 'VariableTypes', varTypes, 'TimeStep', time.step, 'VariableNames', varNames, 'VariableUnits', varUnits);
I am using R2021a, Update 7. As you can see above, I ran the code using the "Run" button here in the forum and got the same error.
I checked the online documentation for making a timetable and 'VariableUnits' is definitely a valid parameter to use. When I omit that part, my code runs fine, and if I check data.Properties, it shows 'VariableUnits' as one of the properties (albeit blank, of course).
What am I doing wrong?
0 个评论
采纳的回答
Star Strider
2022-8-25
For some reason, it doesn’t like 'VariableUnits' as part of the initial timetable declaration.
This alternative approach works —
time.start = duration(0,0,0,0); %Start: 0m, 0s, 0ms
time.end = duration(0,1,0,0); %end: 1m
time.step = duration(0,0,0,1); %step: 1 ms
time.numsteps = (time.end - time.start) / time.step;
varNames = {'Angle','Angular Speed','Voltage','Current','Magnetic Field'};
varTypes = {'double','double','double','double','double'};
varUnits = {'degrees','deg/s','Volts','Amps','Tesla'};
data = timetable('Size', [time.numsteps, 5], 'VariableTypes', varTypes, 'TimeStep', time.step, 'VariableNames', varNames);
data.Properties.VariableUnits = varUnits;
Check = data.Properties.VariableUnits
.
2 个评论
Star Strider
2022-8-25
It very well might be a bug. I had similar problems creating a table recently, although with a different name-value pair. I used the same approach as with your problem.
That aside, the workaround seems to produce the desired result.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!