How to calculate the difference between different values in a table?
조회 수: 10 (최근 30일)
이전 댓글 표시
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
채택된 답변
Vilém Frynta
2023년 2월 8일
편집: Vilém Frynta
2023년 2월 8일
% 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
Vilém Frynta
2023년 2월 8일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!