Group all the columns every N rows
Mostra commenti meno recenti
Hi everyone,
i have an array like this:
A
0.5 0.4 0.5
0.9 0.3 0.5
0.5 0.5 0.1
0.5 0.4 0.2
0.9 0.8 0.2
0.3 0.5 0.2
and i want to create a cell arrays like these (group all the columns every N rows, with N=2):
{A1}
0.5 0.4 0.5
0.9 0.3 0.5
{A2}
0.5 0.5 0.1
0.5 0.4 0.2
{A3}
0.9 0.8 0.2
0.3 0.5 0.2
How can i do it?
Thank you very much!
Risposta accettata
Più risposte (1)
madhan ravi
il 24 Gen 2019
Modificato: madhan ravi
il 24 Gen 2019
One way:
N=2;
[~,c]=size(A);
U=reshape(A',c,N,[]);
R=permute(U,[2 1 3])
4 Commenti
Riccardo Rossi
il 29 Gen 2019
madhan ravi
il 29 Gen 2019
reshape(a,numel(a)/2,[])' % where a your array
Riccardo Rossi
il 29 Gen 2019
madhan ravi
il 29 Gen 2019
I see you have asked another question regarding this issue but here is one solution:
N=4;
[m,c]=size(A);
U=reshape(A',m,[],N);
R=permute(U,[1 3 2]);
BB=reshape(R,N,[],1)'
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!