Operator '-' is not supported for operands of type 'table'
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone.
I have been trying to substract arrays. but I get an error message "
Operator '-' is not supported for operands of type 'table'
for
Q_dot{i} = (Q{i}(2:end,:) - Q{i}(1:end-1,:))./(Time{i}(2:end)-Time{i}(1:end-1))';
And part of the code is shown below. How the operator can be modified to handle this problem ? Or how should I modifit the data type ?
Q_dot = cell(1,6);
% table2array(Quat_dot);
Omg = cell(1,6);
for i=1:6
Q_dot{i} = (Q{i}(2:end,:) - Q{i}(1:end-1,:))./(Time{i}(2:end)-Time{i}(1:end-1))';
Omg{i} = zeros(length(Time{i}),3);
for k=1:length(Time{i})-1
% Something
end
end
Many thanks
采纳的回答
Jonas
2022-7-11
try e.g.
(Quat{i}{2:end,:} - Quat{i}{1:end-1,:})./(Time{i}{2:end}-Time{i}{1:end-1})';
instead of
(Quat{i}(2:end,:) - Quat{i}(1:end-1,:))./(Time{i}(2:end)-Time{i}(1:end-1))';
0 个评论
更多回答(2 个)
Campion Loong
2022-7-22
If you are using table and addressing one variable at a time, dot subscripting (i.e. t.VarName(...) ) is often preferrable to braces (i.e. t{...} ). For one the code is more readable.
0 个评论
Siddharth Bhutiya
2023-3-30
编辑:Siddharth Bhutiya
2023-3-30
The error message in the original question was about '-' not being supported on table. Starting R2023a, tables now support arithmetic operations so you could do things like the following.
T1 = table([1;3],[2;4]);
T2 = table([1;2],[3;4]);
T = T1 - T2
T = (T1 - T2) ./ 10
You can read more about this here: Direct Calculations on Tables and Timetables
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!