I have a simple 5x15 matrix called mat_orig. I would like to divide this matrix into non-overlapping blocks, whereby each block is of length 3. That is equivalent to put three non-overlapping rows into one block (i.e. there are 5 blocks of size 3x5).
I would then like to shuffle mat_orig and generate a new matrix. I am using randi to randomly draw five blocks.
I succeeded in finishing my task using the code below. However, I am wondering if I can get rid of the for-loop? Can I apply vectorization?
mat_orig = reshape(1:75, 5, 15)';
block_length = 3;
num_blocks = size(mat_orig, 1) / block_length;
rand_blocks = randi(num_blocks, num_blocks, 1);
mat_shuffled = nan(size(mat_orig));
for r = 0 : num_blocks - 1
start_row_orig = r * block_length + 1;
end_row_orig = r * block_length + block_length;
start_row_random_blocks = ...
rand_blocks(r + 1) * block_length - block_length + 1;
end_row_random_blocks = ...
rand_blocks(r + 1) * block_length;
mat_shuffled(start_row_orig:end_row_orig, :) = ...
mat_orig(start_row_random_blocks:end_row_random_blocks, :);
end