필터 지우기
필터 지우기

Reshape by rows instead of columns

조회 수: 82 (최근 30일)
Adam Fitchett
Adam Fitchett 2022년 3월 8일
댓글: Amr Aboughazala 2022년 8월 29일
I have a 1260 by 1 column vector (myVector) that I want to reshape to a 35*36 matrix. However, I can't figure out how to reshape it the particular way that I want:
reshape(myVector,35,36) takes each successive chunk of 35 elements from myVector and makes them the 36 columns of the new matrix. But I want to take each successive chunk of 36 elements from myVector and make each chunk the 35 rows of the new matrix. How do I do this?

채택된 답변

Max Alger-Meyer
Max Alger-Meyer 2022년 3월 8일
If I understand you correctly, all you need to do is transpose the reshaped result:
vector = 1:16
vector = 1×16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
array1 = reshape(vector,4,4)
array1 = 4×4
1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
transpose(array1)
ans = 4×4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  댓글 수: 5
Bruno Luong
Bruno Luong 2022년 8월 29일
@Amr Aboughazala "taking the transpose won't give the first answer"
because you take transpose on a wrong reshape.
The correct one is
x = [0,1,2,3,4,5];
reshape(x,[2,3])' % size is [2,3] not [3,2]
ans = 3×2
0 1 2 3 4 5
It does fine.
Amr Aboughazala
Amr Aboughazala 2022년 8월 29일
I just noticed that, thank you so much for your reply :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by