Can't assign VariableUnits to TimeTable
조회 수: 5 (최근 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!