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 commentaires

An example?
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.
Sorry, I had made a mistake.

Connectez-vous pour commenter.

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 12 Sep 2018
Modifié(e) : Andrei Bobrov le 13 Sep 2018
[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 commentaires

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?
Q = reshape(c.',size(c,2),[])'
perhaps
Andrei Bobrov
Andrei Bobrov le 13 Sep 2018
Modifié(e) : Andrei Bobrov le 13 Sep 2018
Please see my answer after edit.
It works. Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by