1
votes

I'm very new to matlab so there could be something blindingly obvious that I'm missing.

Basically, I've got a large dataset matrix (170k x 15) that I need to extract a relatively large amount of subtables from. It's 8 hours of sensor data from a bird that dives into the sea. I need to isolate each instance of the bird diving into the sea. Luckily one of the sensors is a pressure sensor which makes the whole thing much easier, but my problem is that once I've iterated through the data to find an instance of the pressure sensor going up and I've calculated the length and range of the 'dive', I don't know the best way of copying this extract of the matrix into it's own separate set.

What are the best functions for me to be using to simply take twenty rows of the matrix at a time and to put it into it's own unique matrix?

Sorry if this is obvious. I've had a good look around, but nothing seems to be answering my question. For the record, I'm very comfortable at programming. Just new to matlab.

Thanks!

2

2 Answers

0
votes

What are the best functions for me to be using to simply take twenty rows of the matrix at a time and to put it into it's own unique matrix?

You can use mat2cell. For a chunk-size of 20 rows, you can issue:

C = mat2cell(M,repmat(20,1,size(M,1)/20)) 

where M is your original matrix. Demo for a chunk-size of 4:

>> M
M =
  144     2     3
   13   131   130
   25   119   118
  108    38    39
   96    50    51
   61    83    82
   73    71    70
   60    86    87
   48    98    99
  109    35    34
  121    23    22
   12   134   135
>> chunksize = 4;
>> C = mat2cell(M,repmat(chunksize,1,size(M,1)/chunksize)) 
C = 
   [4x3 double]
   [4x3 double]
   [4x3 double]
>> C{2}
ans =
   96    50    51
   61    83    82
   73    71    70
   60    86    87

Each cell of C will contain a 4x3 matrix as illustrated.

0
votes

If you know the rows of the matrix to extract and you want all of the column data, then simply do something like

% create a 25x25 matrix
A = magic(25);

% grab rows 12 through 23
subA = A(12:23,:);

In the above, we specify the number of rows that we want (12:23) and all columns (:).

If you want to create a set of these dives, and you expect that each dive has a different number of rows, you could put the subsets into a cell array

dives  = {};
atDive = 1;

% iterate over data
for k=1:length(A)

     % if found dive start and end, extract and put into cell array
      dives{atDive} = A(diveStart:diveEnd,:);
      atDive        = atDive + 1;

end

Something like the above can be used to store all the dives for further analysis. Try it out and see what happens!