Changing block row matrix to block column matrix?

I have a block matrix p = [A B C ...]. I want to change the matrix into a column block matrix without changing the elements of inner matrices (A, B, ...).

4 个评论

A = [1 2; 3 4];
B = [1 1; 1 1];
C = [3 3; 4 4];
P = [A B C];
I want
Q = [1 2 ;1 1 ;3 3; 3 4 ;1 1 ;4 4];
How can I do it using matrix multiplication or any other functions?
Q = P;
P is already what you list as your desired output.

请先登录,再进行评论。

 采纳的回答

[EDIT]
B = 2; % the number of blocks
[m,n] = size(c);
out = reshape(permute(reshape(c,m,n/B,[]),[1,3,2]),m*B,[]);

4 个评论

The fist one does not work for my case. The reason is as follows:
a = [0.8166 0.8330 0.4215;0.1817 0.4063 0.5333];
b = [0.4303 0.6647 0.5919;0.0024 0.2568 0.3578];
c = [a b];
c = [0.8166 0.8330 0.4215 0.4303 0.6647 0.5919;0.1817 0.4063 0.5333 0.0024 0.2568 0.3578];
So using Q = reshape(c.',2,[])'
Gives
Q = [0.8166 0.8330 0.4215;0.4303 0.6647 0.5919;0.1817 0.4063 0.5333;0.0024 0.2568 0.3578];
as you can see the second row of a has been swapped by the first row of b. I want a and b at one column.
My original problem is as follow:
I have a row block matrix, I know the number of blocks which is N. Hence, c = [a1 a2 a3 a4 ...]. All ai's have the same shape. Without changing the elements of ai's, I want to order them as a column block matrix?
As an example, we can have ai = rand(2,3) i=1:4 b = [a1 a2 a3 a4]. How we can have a block column matrix?
Please see my answer after edit.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by