Create unique matrices from existing matrix using datenum
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I have an ever expanding dataset with each new row being a unique timestamp. Data is continuously collected at 30 second intervals while in operation. At times, there is no operation and so the rows can be quite disconnected.
I would like to extract all columns from the example matrix below if the datenum value is within a certain specification. In this example lets use 30 seconds. If two adjacent rows are 30 seconds or less I want to create a new unique matrix containing all the rows. The data would be split if the two adjacent rows are greater than 30 seconds.
Here is some example data. This is a double matrix.
A = [datenum, data1, data2, data3, data4, data5]
737497.231944445 1408 0 0 0 0
737497.232291667 1409 0 0 0 0
737497.232638889 1410 0 0 0 0
737497.232986111 1411 0 0 0 0
737497.233333333 1412 0 0 0 0
737497.233680556 1413 0 0 0 0
737497.234027778 1414 0 0 0 0
737497.234375000 1415 0 0 0 0
737497.234722222 1416 0 0 0 0
737497.235069444 1417 0 0 0 0
737497.235416667 1418 0 0 0 0
737497.235763889 1419 0 0 0 0
737497.236111111 1420 0 0 0 0
737497.236458333 1421 0 0 0 0
737497.236805556 1422 0 0 0 0
737497.237152778 1423 0 0 0 0
737497.237500000 1424 0 0 0 0
737497.238888889 1425 0 0 0 0
737497.239236111 1426 0 0 0 0
737497.240277778 1427 0 0 0 0
737497.240972222 1428 0 0 0 0
737497.241319445 1429 0 0 0 0
737497.241666667 1430 0 0 0 0
737497.242013889 1431 0 0 0 0
I want to separate A into unique smaller matrices. Each of these unique matices will have the same number of columns, but a different number of rows based on if they are within 30 seconds of each other.
In this case we have 24 total rows. Based on the datenum and 30 seconds = 3.4722e-4 (in datenum format), the data should be separated into 5 new matrices as such
Rows: 1-17, 18-19, 20, 21, 22-24.
I've started to tackle this using a for loop but am unsure of how to proceed.
seconds = 3.4722e-4;
for i=1:length(A)
if A(i+1) - A(i) > seconds
How do I assign unique names to the newly created matrix. It would be grand if I could use the timestamp from the datenum of the first row in the newly creted matrices.
Is this possible?
6 件のコメント
dpb
2019 年 4 月 14 日
How did you generate the datenums? What was the input? If it is really 30 sec differential, then the datenum diff() will be to machine precision of a double not on order of 10E-4.
採用された回答
A. Sawas
2019 年 4 月 13 日
編集済み: A. Sawas
2019 年 4 月 13 日
I am not sure what you are planning to do eventually. However, the following code does what you have explained.
% smallest time step
step = 30;
% convert timestamps into seconds, divide by the time step then do round (ignore time resolutions less than step)
A1 = round(A(:,1)*24*3600/step);
% get the (difference between each two consecutive elements) -1
D = diff(A1)-1;
% cut locations
cutLoc = [0; find(D); size(A1,1)];
% assign the submatrices into cell array
for k=1:numel(cutLoc)-1
subA{k} = A(cutLoc(k)+1:cutLoc(k+1),:);
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!