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

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

4 Kommentare

can you show or append the variables Quat and Time
HN
HN am 11 Jul. 2022
Bearbeitet: HN am 11 Jul. 2022
Thank you @Jonas. It is as in below.
Data{i} = readtable(['20220620/xrd_' S_ID{i} '.txt']);
N_data(i) = height(Data{i});
Pos{i} = Data{i}(:,4:6);
Acc{i} = Data{i}(:,8:10);
Quat{i} = Data{i}(:,11:14);
Time{i}(j) = hour*3600 + minute*60 + sec;
@HN: what do you expect this code to achieve?:
array2table(readtable(..))
HN
HN am 11 Jul. 2022
Bearbeitet: HN am 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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jonas
Jonas am 11 Jul. 2022
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))';

Weitere Antworten (2)

Campion Loong
Campion Loong am 22 Jul. 2022

0 Stimmen

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.
Siddharth Bhutiya
Siddharth Bhutiya am 30 Mär. 2023
Bearbeitet: Siddharth Bhutiya am 30 Mär. 2023
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 = 2×2 table
Var1 Var2 ____ ____ 0 -1 1 0
T = (T1 - T2) ./ 10
T = 2×2 table
Var1 Var2 ____ ____ 0 -0.1 0.1 0
You can read more about this here: Direct Calculations on Tables and Timetables

Kategorien

Gefragt:

HN
am 11 Jul. 2022

Bearbeitet:

am 30 Mär. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by