Reshaping array horizontally elementwise
35 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sushma sharma
am 28 Sep. 2016
Kommentiert: NALLARASU KRISH
am 24 Feb. 2023
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 Kommentare
Image Analyst
am 9 Nov. 2022
@DGM you can use the crossing arrows icon to move posts. This way it retains the original authorship.
DGM
am 9 Nov. 2022
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?
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 28 Sep. 2016
Bearbeitet: Image Analyst
am 28 Aug. 2020
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 Kommentar
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!