How do I reshape a matrix into a vector where each row is positioned end to end?
%example 2d matrix
a = [1 2;3 4]
%this version reshapes columns not rows
b = reshape (a,[1,4])
The result I am looking for is:
Thanks for any assistance.
b = 1 2 3 4

 採用された回答

James Tursa
James Tursa 2020 年 2 月 29 日
編集済み: James Tursa 2020 年 2 月 29 日

1 投票

b = reshape(a.',1,4);
MATLAB array memory is column-wise, so in memory the "a" elements are stored 1,3,2,4. The transpose puts the elements in memory in the order 1,2,3,4 so that the reshape works as you want.

1 件のコメント

Mitchel Stewart
Mitchel Stewart 2020 年 2 月 29 日
Thanks for the quick response!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索

製品

リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by