How to reshape an array in a specific manner

1 Ansicht (letzte 30 Tage)
KostasK
KostasK am 17 Feb. 2020
Kommentiert: dpb am 17 Feb. 2020
Hi all,
I was trying to reshape an array in a specific manner, however I couldn't accomplish that. Here is the example:
I have the following array:
a = [1 ; 2 ; 3 ; 1 ; 2 ; 3 ; 1 ; 2 ; 3 ; 1 ; 2 ; 3] ;
Which I would like to reshape to:
A = [1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3] ;
How can I do this?
I have tried A=reshape(a, 4, 3) however it is returning A=[1 2 3 ; 2 3 1 ; ... etc
Thanks for your help in advance,
KMT

Akzeptierte Antwort

dpb
dpb am 17 Feb. 2020
>> reshape(a,3,[]).'
ans =
1 2 3
1 2 3
1 2 3
1 2 3
>>
  2 Kommentare
KostasK
KostasK am 17 Feb. 2020
thanks for that!
dpb
dpb am 17 Feb. 2020
Remember column-major storage order...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Subhamoy Saha
Subhamoy Saha am 17 Feb. 2020
A=reshape(a,3,4)'

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by