Reshaping array horizontally elementwise

조회 수: 24 (최근 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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by