# Operator '-' is not supported for operands of type 'table'

6 views (last 30 days)
HN on 11 Jul 2022
Answered: Campion Loong on 22 Jul 2022
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
HN on 11 Jul 2022
Edited: HN on 11 Jul 2022
That function is just useless @Stephen23. I just forgot to remove it. But I am not sure if this stil affects my question.

Jonas on 11 Jul 2022
try e.g.
(Quat{i}{2:end,:} - Quat{i}{1:end-1,:})./(Time{i}{2:end}-Time{i}{1:end-1})';
(Quat{i}(2:end,:) - Quat{i}(1:end-1,:))./(Time{i}(2:end)-Time{i}(1:end-1))';

### More Answers (1)

Campion Loong on 22 Jul 2022
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.
Also for reference, this doc topic has some examples on doing Calculations on Data in Tables.