i want to extract rows from a matrix
11 views (last 30 days)
i have a matrix that the number of rows are always even.
i want a code that extracts 2 rows and put them together
s is a matrix that has six rows
i want to extract row 1 and row 2, put them together.
row 3 and row 4, put them together.
row 5 and row 6, put them together.
how can i achieve this?
Animesh Gupta on 8 Jun 2022
It is my understanding that you want to extract adjacent rows of a matrix.
You may refer the following code snippet that demonstrates a procedure to extract adjacent rows.
mat = rand(10,5); % creating an array using rand method
num_of_rows = size(mat,1); % using size method to get the dimensions of matrix along axis 1
new_mat = ;
for i = 1:num_of_rows-1
if mod(i,2) == 1
new_mat = cat(3, new_mat, [mat(i,:); mat(i+1,:)]); % using cat method to append along the 3rd dimension of the new matrix
% You can access the individual 2d sub-arrays as:
I hope it helps.