How to calculate the difference between different values in a table?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I'm trying to calculate the time differences/lag between event 'ENDSACC' and '1002' (in the message), using the time of each ENDSACC to subtract the time of each 1002.
For example:For the first '1002', its time lag : 'ENDSACC'(2) (72-942= -870) 'ENDSACC'(3) (356-942= -586) 'ENDSACC'(6) (1032-942= 90).
Only the number is important so the ideal result would be like;
-870 -586 90 ...
How can I do such calculation, thanks for any help.
0 Commenti
Risposta accettata
Vilém Frynta
il 8 Feb 2023
Modificato: Vilém Frynta
il 8 Feb 2023
% loading data and separating useful data from useless data
load Foveal.mat
T = ans; % your table
T_1002 = T(matches(T.message,'1002'),:) % table with only "1002"
T_ENDSACC = T(matches(T.message,'ENDSACC'),:) % table with only "ENDSACC"
% creating matrix before for loop
[x1 ~] = size(T_1002);
[x2 ~] = size(T_ENDSACC);
T_diff = zeros(x1,x2); % will create 5x57 matrix
% doing the calculations and saving them into 5x57 matrix
for q = 1:x1
T_diff(q,:) = int32(T_1002.reltime(q)) - int32(T_ENDSACC.reltime(:));
end
% first row is first1002 vs. endsacc times, second row is second 1002 vs. endsacc times, ...
T_diff
4 Commenti
Vilém Frynta
il 8 Feb 2023
I had a bit of time and I found the fix.
New version of the for loop should work:
for q = 1:x1
T_diff(q,:) = int32(T_1002.reltime(q)) - int32(T_ENDSACC.reltime(:));
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!