Split table from database into sub-tables dependent from timestamp difference
이전 댓글 표시
Hi there,
I'm importing measurement data from a PostgreSQL database into one Matlab table, called data:
%% Make connection to database
conn = database('PostgreSQL','NameOfDatabase','Password');
%Set query to execute on the database
query = ['SELECT * ' ...
'FROM postgres.public.data'];
%% Execute query and fetch results
data = fetch(conn,query);
the data table looks like this:
timestamp ID x y z
'2019-07-22 15:46:24.919' 41034 32.5437012000000 6.59714985000000 0
'2019-07-22 15:46:25.019' 41034 32.5466003000000 6.59952021000000 0
'2019-07-22 15:46:25.119' 41034 32.5657997000000 6.60097980000000 0
'2019-07-22 15:46:25.219' 41034 32.5840988000000 6.59719992000000 0
'2019-07-22 15:46:25.319' 41034 32.5975990000000 6.59470987000000 0
'2019-07-22 15:46:25.419' 41034 32.6068001000000 6.59368992000000 0
'2019-07-22 15:46:25.519' 41034 32.6091003000000 6.59696007000000 0
'2019-07-22 15:46:25.619' 41034 32.6016006000000 6.59864998000000 0
'2019-07-22 15:46:25.719' 41034 32.5957985000000 6.59865999000000 0
Now I want to create a new table for each measurement. I can only distinguish the next measurement from a time difference (of a few seconds) in the timestamp column. This is somehow what I'm trying:
format long
data.timestamp = categorical(data.timestamp);
Difference = caldiff(data.timestamp);
Tablename = ('Mess' + 'Counter');
Counter = 0;
for each Difference > 2 seconds
% create new table (Tablename)
% insertrows from start to difference row
Counter = Counter + 1;
end
Is caldiff the right funktion for the very small time differences?
Thanks
댓글 수: 1
Stephen23
2019년 7월 24일
"Now I want to create a new table for each measurement"
Why?
MATLAB tables are designed to make it easy to group data and apply operations on those groups:
https://www.mathworks.com/help/matlab/matlab_prog/split-table-data-variables-and-apply-functions.html
In contrast, splitting up data like that usually just makes it harder to work with.
What is your actual goal? How do you wish to process your data?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!