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 件のコメント

madhan ravi
madhan ravi 2018 年 9 月 12 日
An example?
Seyyed Mohammad Saeed Damadi
Seyyed Mohammad Saeed Damadi 2018 年 9 月 12 日
編集済み: Seyyed Mohammad Saeed Damadi 2018 年 9 月 12 日
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?
Walter Roberson
Walter Roberson 2018 年 9 月 12 日
Q = P;
P is already what you list as your desired output.
Seyyed Mohammad Saeed Damadi
Seyyed Mohammad Saeed Damadi 2018 年 9 月 12 日
Sorry, I had made a mistake.

サインインしてコメントする。

 採用された回答

Andrei Bobrov
Andrei Bobrov 2018 年 9 月 12 日
編集済み: Andrei Bobrov 2018 年 9 月 13 日

2 投票

[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 件のコメント

Seyyed Mohammad Saeed Damadi
Seyyed Mohammad Saeed Damadi 2018 年 9 月 12 日
編集済み: Walter Roberson 2018 年 9 月 12 日
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?
Walter Roberson
Walter Roberson 2018 年 9 月 12 日
Q = reshape(c.',size(c,2),[])'
perhaps
Andrei Bobrov
Andrei Bobrov 2018 年 9 月 13 日
編集済み: Andrei Bobrov 2018 年 9 月 13 日
Please see my answer after edit.
Seyyed Mohammad Saeed Damadi
Seyyed Mohammad Saeed Damadi 2018 年 9 月 13 日
It works. Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by