# Extract a series of values every n row of a matrix

2 views (last 30 days)
Silvia Marchesi on 14 Jun 2022
Commented: Silvia Marchesi on 14 Jun 2022
Hello, I have a matrix with the following dimensions 154353x3.
I would need to extract 2180 rows every 2580 rows (that means that I 2180 rows that I need to analyze, then 399 rows I do not need to analyze, then another 2180 rows I need to analyze and so on).
How is the most effective way to extract only the segments I have to analyze?
Silvia
##### 2 CommentsShowHide 1 older comment
Silvia Marchesi on 14 Jun 2022
Serially, 2180 to analyze, then 399 to not analyze, then 2180 to analyze and so on...

DGM on 14 Jun 2022
Consider the small example:
% a small 100x3 test array
A = repmat((1:100).',[1 3])
A = 100×3
1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10
% parameters
blocksize = 10;
rowstokeep = 7;
% reshape and truncate
A = reshape(permute(A,[1 3 2]),blocksize,[],3);
A = permute(A(1:rowstokeep,:,:),[1 3 2])
A =
A(:,:,1) = 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 A(:,:,2) = 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 17 17 17 A(:,:,3) = 21 21 21 22 22 22 23 23 23 24 24 24 25 25 25 26 26 26 27 27 27 A(:,:,4) = 31 31 31 32 32 32 33 33 33 34 34 34 35 35 35 36 36 36 37 37 37 A(:,:,5) = 41 41 41 42 42 42 43 43 43 44 44 44 45 45 45 46 46 46 47 47 47 A(:,:,6) = 51 51 51 52 52 52 53 53 53 54 54 54 55 55 55 56 56 56 57 57 57 A(:,:,7) = 61 61 61 62 62 62 63 63 63 64 64 64 65 65 65 66 66 66 67 67 67 A(:,:,8) = 71 71 71 72 72 72 73 73 73 74 74 74 75 75 75 76 76 76 77 77 77 A(:,:,9) = 81 81 81 82 82 82 83 83 83 84 84 84 85 85 85 86 86 86 87 87 87 A(:,:,10) = 91 91 91 92 92 92 93 93 93 94 94 94 95 95 95 96 96 96 97 97 97
The blocks are now arranged along dim3, excess rows are omitted.
Silvia Marchesi on 14 Jun 2022
Many thanks!