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

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.

댓글을 달려면 로그인하십시오.

 채택된 답변

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

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 2018년 9월 13일
편집: Andrei Bobrov 2018년 9월 13일
Please see my answer after edit.
It works. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (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