Identify the maximum values within fixed time intervals of a time series data set
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Askeladden2
am 26 Jan. 2024
Kommentiert: Star Strider
am 30 Jan. 2024
Dear all fellow community members,
I have a matrix of dimensions 20x74932, signifying 20 variables within a time series sampled at 3000 Hz. Additionally, there is a corresponding time matrix sized 20x74932. The time matrix varies in accordance with the variables. In other words, only events are logged in the variables. For instance, for the first variable, a peak load occurs after 800 seconds, followed by the next peak load at 1550 seconds, then at 18000 seconds, and so forth.
For the second variable, the first peak load appears after 300 seconds, with the subsequent one at 1200 seconds, and so on.
My objective is to ascertain the highest peak load for each 20-minute interval throughout the entire time series. For example, if there are 2 peak loads within the first 0 to 20 minutes, I wish to retain only the highest. Subsequently, I want to keep the highest peak load from 20 minutes to 40 minutes and continue in this manner until the end of the time series.
Below is a hypothetical example for your reference:
Time=[4 5 6 7 8 9 10 25 26 27 28 29 46 47 48 49 50 58 59 60; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0 0 ; 1 2 3 4 5 6 7 8 9 10 11 12 0 0 0 0 0 0 0 0]; %Time vector, in minutes
x=[ 0 5 0 1 3 11 2 0 0 1 8 3 0 0 -5 12 2 -2 14 13; 0 0 0 0 0 0 0 15 0 1 -2 0 8 0 3 2 0 18 0 0; 0 8 -1 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0]; %Variables of peak loads
As mentioned, my aim is to extract the highest peak load per 20-minute interval, which means I am seeking the following results;
0 min - 20min – 11 18 25
20min - 40min – 8 0 0
40min - 60min – 14 0 0
Any help is very appreciated! Thanks.
The example I provided was not 100% representative for my problem. I should have specified the time vector as a matrix, in order to demonstrate a varying time vector for each variable. I have therefore changed the time. This will also influence the results, which are also updated.
I really appreciate all your time and efforts, and apologize for providing an incorrect example to my actual problem.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Jan. 2024
Bearbeitet: Star Strider
am 26 Jan. 2024
Try this —
Time=[4 5 6 7 8 9 10 25 26 27 28 29 46 47 48 49 50 58 59 60]; %Time vector, in minutes
x=[ 0 5 0 1 3 11 2 0 0 1 8 3 0 0 -5 12 2 -2 14 13; 0 0 0 0 0 0 0 15 0 1 -2 0 8 0 3 2 0 18 0 0; 0 8 -1 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0];
interval = ceil(Time/20)
Rcell = accumarray(interval(:), (1:numel(interval)).', [], @(v){max(x(:,v).')});
Column_ = cell2mat(Rcell)
intv = 0:numel(Rcell);
rn = compose('% 2d min - %2d min — ',[intv(1:end-1); intv(2:end)].'*20);
Results = array2table(Column_, 'RowNames',rn)
EDIT — (26 Jan 2024 at 15:20)
Added ‘Results’ table.
.
8 Kommentare
Star Strider
am 30 Jan. 2024
As always, my pleasure!
That was the update required to use the offset vector in ‘Part Two’ earlier, where I added it originally.
My ‘Part Two’ code is much more robust that my original ‘Part One’ code.
Weitere Antworten (2)
Catalytic
am 26 Jan. 2024
Bearbeitet: Catalytic
am 26 Jan. 2024
Time=[4 5 6 7 8 9 10 25 26 27 28 29 46 47 48 49 50 58 59 60]; %Time vector, in minutes
x=[ 0 5 0 1 3 11 2 0 0 1 8 3 0 0 -5 12 2 -2 14 13; 0 0 0 0 0 0 0 15 0 1 -2 0 8 0 3 2 0 18 0 0; 0 8 -1 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0]; %Variables of peak loads
T=timetable(minutes(Time(:)), x');
% Retime timetable
newTimetable = retime(T,"regular","max","TimeStep",minutes(20),...
'IncludedEdge','right')
1 Kommentar
Morgan
am 26 Jan. 2024
% INTERVAL TO SAMPLE
Interval = 20;
% TIME ARRAY
Time = [ 4 5 6 7 8 9 10 25 26 27 28 29 46 47 48 49 50 58 59 60 ];
% CALCULATE NUMBER OF INTERVALS
numIntervals = 1 + floor((Time(end) - Time(1))/Interval);
% CALCULATE INDICES FOR TIME ARRAY INTERVALS
startIdx = zeros(numIntervals,1);
endIdx = zeros(numIntervals,1);
for n = 1 : numIntervals
startIdx(n) = find(Time >= (n-1)*Interval, 1, 'first');
endIdx(n) = find(Time < n*Interval, 1, 'last');
end
% VARIABLES OF PEAK LOADS
x = [ 0 5 0 1 3 11 2 0 0 1 8 3 0 0 -5 12 2 -2 14 13 ; ...
0 0 0 0 0 0 0 15 0 1 -2 0 8 0 3 2 0 18 0 0 ; ...
0 8 -1 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0 ];
% CALCULATE NUMBER OF VARIABLES
nvars = size(x,1);
% CALCULATE ARRAY A MAXIMUM PEAK LOAD VALUES
% AT EACH INTERVAL
maxValues = zeros(nvars,numIntervals);
for n = 1 : numIntervals
maxValues(:,n) = max(x(:,startIdx(n):endIdx(n)),[],2);
end
disp(maxValues)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!