Another way to convert a matrix in a single vector

1 回表示 (過去 30 日間)
Jose Antonio  Salcedo Simon
Jose Antonio Salcedo Simon 2018 年 2 月 26 日
回答済み: Bhuvnesh Singh 2018 年 2 月 28 日
Hi sirs,
I am trying to convert a matrix into a single vector through the syntax ":" or "reshape", but they do not work as I want. They work column by column, but I want row by row, like this:
Is there any way to do this?
Thank you very very for the reply. All the best.

回答 (1 件)

Bhuvnesh Singh
Bhuvnesh Singh 2018 年 2 月 28 日
In order to achieve this, you can first take the transpose of the matrix and then apply reshape method on it.
Lets say a = [1 2; 3 4]
b = a'
vec = b(:)
You can also follow the below link: https://www.mathworks.com/matlabcentral/answers/54172-how-to-flatten-a-matrix-in-row-major-order

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by