How to calculate the difference between different values in a table?
2 ビュー (過去 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!