Selecting and filtering a range of rows periodically
2 views (last 30 days)
Show older comments
I have a large array of 819600 rows and 3 columns. I simply just want to extract 'segments' or 'groups' of rows to a different array from this large array. There are about 683 such 'segments' and each segment is 1200 rows. Let's call this 1200 rows as 'preamble' and the remaining 7200 as 'data' How do i create the appropriate indexing to extract these and 1200 rows of preamble and 7200 rows as data which keep repeating periodically one after the other in the 819600 rows? Here is a more clear explanation
0th row -------------------------------------------------------------------------------------------------------> 819600 row
preamble data preamble data
|-------| |------------------------| |-------| |------------------------| ......-------------------------> end(819600th row)
1200 7200 1200 7200
I think i am close, but just need some expert/MVP to guide me. I have already looked at the following links which were asked previosly, but not exactly getting to what i want.
I know my answer lies with possibly a combination of the above links suggested solutions. I think the fastest(most compute efficient) way of doing this would be something like this below which is using similar method as the second link...but as you might see, it's impractical keep creating 683 index ranges. In the example below there are only 3 index ranges.
A = rand(819600,3);
ind_logical = logical(ones(819600,1));
ind_logical([1:1200, 7201:8401, 15601:16881])=false;
B = A(~ind_logical,:);
C = A(ind_logical,:);
Thank you,
Iroquois
0 Comments
Accepted Answer
Jan
on 9 Mar 2021
In your case the data length 7200 is a multiple of 1200 by accident. This can be used:
A = rand(819600, 3);
n = size(A, 1) / 1200;
B = permute(reshape(A, 1200, n, 3), [2, 1, 3]);
Preambel = B(1:6:end, :, :);
Data = B;
Data(1:6:end, :, :) = [];
Data = reshape(Data, n / 6, [], 3);
Sorry, this does not run. Your 819600 data points cannot be divided in blocks of 1200+7200=8400 without a rest. Please explain this. If A has 819600 - 4800 columns, it will work.
Another approach:
m = zeros(1, 819600 - 4800);
m(1:8400:end) = 1;
m(1201:8400:end) = -1;
m = cumsum(m);
Preamble = reshape(A(m == 1, :), [], 1200, 3);
Data = reshape(A(m == 0, :), [], 7200, 3);
3 Comments
Jan
on 10 Mar 2021
Yes, I meant "rows", not columns.
You have to find the first valid preamble and then an integer number of repetitions of preambels and data. The final frames can be cut off also. I do not know, how a preamble can be identified.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!