Semi-transpose a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dear Matlab Experts,
I want to block-transpose a matrix i.e. a set of elements are forming a block of elements. My goal is to transpose the blocks such that within each block, the order of elements remains unchanged. I guess the below example helps to clarify my question:
a = [1 2 3 4 5 6
0 3 2 1 2 3
0 0 0 1 1 1
8 9 9 1 2 3]
Now,Assume that each row plays a role of a block thus the matrix a has 4 blocks with the size of 4*1 that is,
a = [block1; block2; block3; block4]
I need to transpose in the block-based order so the desired outcome has the following form:
[1 2 3 4 5 6 0 3 2 1 2 3 0 0 0 1 1 1 8 9 9 1 2 3]
Your helps will be appreciated. Thank you so much
0 comentarios
Respuestas (2)
Andrei Bobrov
el 12 de Jul. de 2016
Editada: Andrei Bobrov
el 12 de Jul. de 2016
" blocks are the matrix of 2*3"
[m,n] = size(a);
p = 2;
q = 3;
out = cell2mat(mat2cell(a,p*ones(m/p,1),q*ones(n/q,1))');
or
a = [1 2 3 4 5 6
0 3 2 1 2 3
0 0 0 1 1 1
8 9 9 1 2 3];
[m,n] = size(a);
p = 2;
q = 3;
t = reshape(a,p,m/p,q,n/q);
z = permute(t,[1 4 3 2]);
out = reshape(z,n/q*p,[])
0 comentarios
Azzi Abdelmalek
el 12 de Jul. de 2016
Editada: Azzi Abdelmalek
el 12 de Jul. de 2016
a = [1 2 3 4 5 6
0 3 2 1 2 3
0 0 0 1 1 1
8 9 9 1 2 3]
b=a'
b=b(:)'
Or
b=reshape(a',1,[])
2 comentarios
Azzi Abdelmalek
el 12 de Jul. de 2016
You can use cell arrays
b1=randi(10,4)
b2=randi(10,4)
b3=randi(10,4)
b4=randi(10,4)
A={b1,b2;b3,b4}
idx=reshape(1:numel(A),size(A))'
out=cell2mat(A(idx))
Ver también
Categorías
Más información sobre Wind Power en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!