How to reshape a matrix into nx2 matrix?

1 回表示 (過去 30 日間)
gsourop
gsourop 2019 年 11 月 1 日
編集済み: Adam 2019 年 11 月 1 日
Hi everyone,
I would like to reshape matrix A
A = magic(6)
ans =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
into a new matrix with the following output:
A1 = 35 1
3 32
31 9
8 28
30 5
4 36
6 26
7 21
2 22
33 17
34 12
29 13
19 24
23 25
27 20
10 15
14 16
18 11
Thank you.

採用された回答

Adam
Adam 2019 年 11 月 1 日
編集済み: Adam 2019 年 11 月 1 日
reshape( A( :, [ 1:2:end, 2:2:end ] ), [], 2 )
You may wish to change the final two arguments to the reshape command in different situations.
doc reshape
tells you about these.
You can be explicit and pass in the exact size as [18, 2] or 18, 2 if you wish or you could pass in 18, []
In this case all would give the same answer. The [] input is allowed for one dimension and just tells it to work out that value in order to use all elements. Obviously the product of all the dimensions you resize to must be equal to the number of elements in the array being resized.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by