Azzera filtri
Azzera filtri

Reshape and rearrange elements of a matrix

1 visualizzazione (ultimi 30 giorni)
Amine be
Amine be il 10 Apr 2018
Risposto: Birdman il 10 Apr 2018
Hi all,
I want to reshape the dimension of a matrix and to put its elements in a specific order.
let say that we have A=[1 2 3 4 5 6 ; 7 8 9 10 11 12].
I want to have a matrix B= [1 2 3; 7 8 9; 4 5 6; 10 11 12].
What's the best way to do this?

Risposte (2)

M
M il 10 Apr 2018
For your example, you could use something like this:
A=[1 2 3 4 5 6; 7 8 9 10 11 12];
B=[reshape(A(:,1:end/2),2,3);reshape(A(:,end/2+1:end),2,3)]
B =
1 2 3
7 8 9
4 5 6
10 11 12
and generalize it to other example.

Birdman
Birdman il 10 Apr 2018
B=reshape(A.',3,4).';%temp
B(2:3,:)=flipud(B(2:3,:))

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by