How to calculate the difference between different values in a table?
조회 수: 15 (최근 30일)
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.
Vilém Frynta 2023년 2월 8일
편집: Vilém Frynta 님. 2023년 2월 8일
% loading data and separating useful data from useless data
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(:));
% first row is first1002 vs. endsacc times, second row is second 1002 vs. endsacc times, ...