1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
IceQueeny
  • 154
  • 1
  • 10
  • 1
    Can you provide small example data and the corresponding output for it? – nrz Apr 02 '13 at 14:05
  • Well Ii have a structure with 3 columns: time voltage current. I put time and current in vectors to work with. So i probably would prefer to create new vectors for time and current times 9. The time is still in seconds after 1970 jan 1 00:00:00. But that shouldn't matter. Data ranges from 10^(-9) to 10^(-6) for this one. Times is bigger ;) – IceQueeny Apr 02 '13 at 14:13

2 Answers2

1

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
user1884905
  • 3,137
  • 1
  • 22
  • 22
  • yes that seems like a nice solution to work with.. then I can just tell which columns to use.. I will try it out directly :) – IceQueeny Apr 02 '13 at 14:32
  • well I have a new problem since my data is not always reshapeable (wrong number of elements to fit this..) 'Error using reshape To RESHAPE the number of elements must not change.' I guess it is because that my first or last dataset is small then the others.. is there a way to do go around that? :S – IceQueeny Apr 02 '13 at 15:09
  • @IceQueeny A simple solution would be to pad with zeros to get signals of equal length. You could also try to create a `groupingVariable` (perhaps using `cumsum()` on the gap-indices as in `grpVar=cumsum(w)`). And then distinguishing between the different data-sets using `Tdat(grpVar==1), Tdat(grpVar==2), ...`. – user1884905 Apr 02 '13 at 19:54
0

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.

IceQueeny
  • 154
  • 1
  • 10