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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Guillaume
Guillaume il 2 Feb 2016
Modificato: Guillaume il 2 Feb 2016
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 Commenti
Guillaume
Guillaume il 3 Feb 2016
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by