Reshaping array horizontally elementwise

34 ビュー (過去 30 日間)
sushma sharma
sushma sharma 2016 年 9 月 28 日
コメント済み: NALLARASU KRISH 2023 年 2 月 24 日
Hi,
I have a 1 x 100 array, A. How can I reshape it so that I have a 10 x 10 double so that the first ten elements are the first row, second ten element are the second row, etc.
I tried reshape(A, [10,10]) but that arranged them down columns instead of rows. Any help would be appreciated!
Sushma
  4 件のコメント
Image Analyst
Image Analyst 2022 年 11 月 9 日
@DGM you can use the crossing arrows icon to move posts. This way it retains the original authorship.
DGM
DGM 2022 年 11 月 9 日
I should have mentioned that it was a comment-as-flag, not a normal answer or comment. As I mentioned in the thread on the new feature, I wish it would apply to flags as well. For some reason, I couldn't get it to @user his name either. Maybe because he has no other activity?

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

採用された回答

sushma sharma
sushma sharma 2016 年 9 月 28 日
got it!
reshape(A, 10 [])'

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 9 月 28 日
編集済み: Image Analyst 2020 年 8 月 28 日
Try optionally transposing the array first before and after reshaping and see what you get. Try several different ways - it's the best way to learn.
M = 1:100 % Row vector.
M1 = reshape(M, 10, [])
M2 = reshape(M, 10, [])'
M3 = reshape(M', 10, [])
M4 = reshape(M', 10, [])'
M1 =
1 11 21 31 41 51 61 71 81 91
2 12 22 32 42 52 62 72 82 92
3 13 23 33 43 53 63 73 83 93
4 14 24 34 44 54 64 74 84 94
5 15 25 35 45 55 65 75 85 95
6 16 26 36 46 56 66 76 86 96
7 17 27 37 47 57 67 77 87 97
8 18 28 38 48 58 68 78 88 98
9 19 29 39 49 59 69 79 89 99
10 20 30 40 50 60 70 80 90 100
M2 =
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
M3 =
1 11 21 31 41 51 61 71 81 91
2 12 22 32 42 52 62 72 82 92
3 13 23 33 43 53 63 73 83 93
4 14 24 34 44 54 64 74 84 94
5 15 25 35 45 55 65 75 85 95
6 16 26 36 46 56 66 76 86 96
7 17 27 37 47 57 67 77 87 97
8 18 28 38 48 58 68 78 88 98
9 19 29 39 49 59 69 79 89 99
10 20 30 40 50 60 70 80 90 100
M4 =
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
  1 件のコメント
NALLARASU KRISH
NALLARASU KRISH 2023 年 2 月 24 日
Very apt answer. Keep it up!

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

カテゴリ

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