I have a data set as below , How can i assign T values : 49 as 1 and 53 as 5 and so on considering the gap between the time (49,53,54...10,16) in seconds, it is always not 4 s at the begining and end , it vary as 2 s , 3 s, and so on... i would be

조회 수: 1 (최근 30일)
T(s) Cnt
49.00 804.00
53.00 717.00
54.00 613.00
55.00 603.00
56.00 630.00
57.00 580.00
58.00 566.00
59.00 643.00
1.00 672.00
2.00 651.00
3.00 675.00
4.00 650.00
5.00 653.00
6.00 605.00
7.00 567.00
8.00 678.00
9.00 760.00
10.00 824.00
16.00 798.00

채택된 답변

Guillaume
Guillaume 2016년 2월 2일
편집: Guillaume 2016년 2월 2일
Assuming your data is held in a matrix as follows:
data = [49.00 804.00
53.00 717.00
54.00 613.00
55.00 603.00
56.00 630.00
57.00 580.00
58.00 566.00
59.00 643.00
1.00 672.00
2.00 651.00
3.00 675.00
4.00 650.00
5.00 653.00
6.00 605.00
7.00 567.00
8.00 678.00
9.00 760.00
10.00 824.00
16.00 798.00];
The difficulty comes from your time wrapping around back to 0 after 60 seconds. You can cope with that by calculating the time difference between rows modulo 60:
timeoffsets = mod(diff(data(:, 1)), 60);
To get back to your time but starting at 1, you can then cumsum these offsets:
data(:, 1) = [0; cumsum(timeoffsets)] + 1
  댓글 수: 5
Guillaume
Guillaume 2016년 2월 3일
Your algorithm will break if the time span of a file is greater than a minute since you may get identical seconds that belong to different minutes. unique will consider the same. While there are ways to cope with this if you assume identical seconds are consecutive, it seems to me that the easiest thing is to simply not discard the hour and minute information.
I don't know how you read your file but the following would work:
data = readtable('Data.txt', 'ReadVariableNames', false); %or use textscan
hms = regexp(data.Var6, '(\d+)-(\d+)-(\d+)', 'tokens', 'once');
hms = str2double(vertcat(hms{:}));
[hms, ~, rows] = unique(hms, 'rows');
summeddata = zeros(size(hms, 1), 4);
for column = 2:5
summeddata(:, column-1) = accumarray(rows, data{:, column});
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by