Filter löschen
Filter löschen

how to convert 2-D array to 1-D array

4 Ansichten (letzte 30 Tage)
Ashraf Hisham
Ashraf Hisham am 17 Apr. 2018
Kommentiert: Guillaume am 17 Apr. 2018
how to convert 2-D array of dimension n*m to 1-D array with length (n*m) if a=[1 2 3;4 5 6;7 8 9] i want a = [1 2 3 4 5 6 7 8 9] so how

Akzeptierte Antwort

Guillaume
Guillaume am 17 Apr. 2018

transpose then reshape

a = reshape(a.', 1, [])

Weitere Antworten (1)

Bosong Lin
Bosong Lin am 17 Apr. 2018
Hey,
Try this. A = [1,2;3,4]; A = A(:);
  1 Kommentar
Guillaume
Guillaume am 17 Apr. 2018
Ashraf wants the reshaping done by row, this would do it by column which is not what is asked. It produces [1;3;2;4] instead of [1,2,3,4]

Melden Sie sich an, um zu kommentieren.

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