How to calculate the difference between different values in a table?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JCH
el 8 de Feb. de 2023
Comentada: Vilém Frynta
el 8 de Feb. de 2023
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 comentarios
Respuesta aceptada
Vilém Frynta
el 8 de Feb. de 2023
Editada: Vilém Frynta
el 8 de Feb. de 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 comentarios
Vilém Frynta
el 8 de Feb. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!