Extract sub-matrices from a big matrix

1 次查看(过去 30 天)
I have an example matrix like the one given below. Original size of my matrix is (83193 x 2). I want extract every 2 rows and make a 2 x 2 matrix from this big matrix. For example:
[1 2
3 4
5 6
7 8
9 10
11 12]
Changed into:
A = [1 2; 3 4]
B = [5 6; 7 8]
C = [9 10; 11 12]
How can I do this operation?
Thanks!

采纳的回答

Jan
Jan 2017-3-29
X = rand(83193, 2);
s1 = size(X, 1);
XX = X(1:s1 - rem(s1, 2), :); % Number of blocks needs to be multiple of 2
Y = permute(reshape(XX, 2, [], 2), [1, 3, 2]);
Now Y(:, :, i) is the i.th 2x2 matrix. This is much more efficient than creating 41596 variables.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by