How do I write a for loop that stacks the columns of a matrix vertically into a single column array?

3 ビュー (過去 30 日間)
Elias Beaini
Elias Beaini 2018 年 1 月 24 日
回答済み: ag 2024 年 12 月 4 日
I have a 3x4 matrix and I need to stack the columns in order into a vertical stack.

回答 (1 件)

ag
ag 2024 年 12 月 4 日
Hi Elias,
To reshape the matrix into a column vector, you can use the colon operator.
The below code demonstrates the same:
A = [1 2 3 4;
5 6 7 8;
9 10 11 12]
A = 3×4
1 2 3 4 5 6 7 8 9 10 11 12
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
stackedMatrix = A(:)
stackedMatrix = 12×1
1 5 9 2 6 10 3 7 11 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Hope this helps!

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by