Data manipulation: "Stitching" together a time series
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello. I have a slight data manipulation problem:
I have a few time series, where the timing (many more to come) looks like this:
14.243 30.212 . . . 980.563 (new round) 7.823 18.959 . . . 786.34 (new round) ... You get the picture, right?
There is an arbitrary number of intervals between the different "time-spikes", which makes it look like this:

Now, how do I "fuse" or "stitch" together the "peak" to the first obs. of the next round, so that i get a meaningful timeline?
Thanks in advance! T
0 Kommentare
Antworten (2)
Star Strider
am 7 Jan. 2015
I’m not certain how your data are organised, so this is just a guess:
t = [1:10; 11:20; 21:30]; % Original Time Matrix
tr = reshape(t', 1, []); % Sequential Time Vector
y = [1:10; 1:10; 1:10]; % Original Data Matrix
ye = cumsum([0; y(2:end,end)]); % Find End Values & Sum
ys = bsxfun(@plus, y, ye); % Add End Values To ‘y’
yr = reshape(ys', 1, []); % Create Sequential Data Vector
figure(1)
subplot(2,1,1)
plot(t', y')
grid on
subplot(2,1,2)
plot(tr, yr)
grid on
It has the virtue of working, and will at least provide you with one possible solution.
2 Kommentare
Star Strider
am 22 Jan. 2015
Bearbeitet: Star Strider
am 22 Jan. 2015
My pleasure.
Did you run my code on your data? The distance between the peaks should not be a problem.
If my code did not work with your data, I need to know what the problem was. Otherwise, you may need to save your data to a .mat file and attach it here in order for me to adapt my code to work with it.
Guillaume
am 22 Jan. 2015
Bearbeitet: Guillaume
am 22 Jan. 2015
Rule 1: Don't stick your time series into individual variables. Stick them into a cell array:
tseries = {var1 var2 var3 var4 ...};
It makes it so much easier to process them all at the same time.
It's then a matter of cumsum ing the last and first value of each vector, and adding that to the next vector minus the first value of the vector:
tseries = {1:100 3:60 7:25 2:63}; %demo data
ends = [0 cumsum(cellfun(@(v) v(end), tseries(1:end-1)))]; %cumsum end of each array (without last one)
starts = [0 cumsum(cellfun(@(v) v(1), tseries(2:end)))];
tseries = cellfun(@(v, e, s) v+e-s, tseries, num2cell(ends), num2cell(starts), 'UniformOutput', false); %add offset
0 Kommentare
Siehe auch
Kategorien
Mehr zu Time Series Events 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!