Reputation: 154
I have some data with gaps in the time series. The indices of the gaps are found and also length and everything. The thing is that I would like to chop up my data (columns: time and measurements) into either several matrices/vectors or chop it up in a structure. My plan is to Fourier transform these small time series for further comparisons.
Lets try to explain in en example: Tdat is the timeseries and has 3825 points
% find number of gaps
nogap = diff(Tdat(find(diff(Tdat)>0.051))); %20Hz measurement
numgaps = length(nogap) %number of gaps = bumgaps+1
the number of gaps here is 8
%indexing the gaps
w = find(diff(Tdat)>0.51); %finding the gaps %0.051 since 1/20=0.05
u = find(diff(Tdat)<0.51); %finding indices with data
series = length(M)-length(u) %amount of data series without gaps
number of data series without gaps is 9
delta = diff(w) %amount of points between two gaps (constant
the amount of points in between those gaps is 425.
Thus I would like to have 9 different matrices/vectors with only the data and no time gaps each length 425.
Is there some way or haven't I searched good enough to find an answer?
Upvotes: 1
Views: 131
Reputation: 154
Well I found another answer which turned out to be more useful in the end. In case someone is interested.
Since not always all part (without the gap) are of equal length it is hard to keep track of all the indices needed to fill some columns with zeros.
Since I know where all the gaps start I can just use a new indexing to put those into structures.
gl = find(diff(Tdat)>0.051);
gaps = length(gl)-1;
for a = 1:gaps;
Meas(a).M = M( gl(a)+1 : gl(a+1) );
end
where Tdat is my time vector and M is the vector with the data.
Upvotes: 0
Reputation: 3137
From what I can see from your example it seems like the gaps are not data points you want to remove, but places to divide your data? Am I right? Since the resulting data-vectors are the same length, perhaps you want to reshape()
your vector? As in reshape(Tdat,425,9)
.
Here is a small example:
>> a = [1:12]'
a =
1
2
3
4
5
6
7
8
9
10
11
12
>> b = reshape(a,4,3)
b =
1 5 9
2 6 10
3 7 11
4 8 12
You could also use mat2cell()
afterwards if you want the data as a cell:
>> c = mat2cell(b,4,ones(1,3))
c =
[4x1 double] [4x1 double] [4x1 double]
>> c{2}
ans =
5
6
7
8
Upvotes: 1