How to rearrange 2x5 matrix while keeping the size the same?

조회 수: 1 (최근 30일)
Wei Yow
Wei Yow 2023년 4월 28일
댓글: Wei Yow 2023년 4월 28일
Hi,
How do I tranpose such that
x = [1, 5, 9, 4, 8; 3, 7, 2, 6, 10] to
x =[1, 3, 5, 7, 9 ; 2, 4, 6, 8, 10]
while keeping the 2x5 matrix? This matrix was returned from a function reading a file consisting of a row-oriented data.
thank you.

채택된 답변

Stephen23
Stephen23 2023년 4월 28일
편집: Stephen23 2023년 4월 28일
Rather than sorting the data, I suspect that you want something like this:
x = [1, 5, 9, 4, 8; 3, 7, 2, 6, 10]
x = 2×5
1 5 9 4 8 3 7 2 6 10
y = reshape(x,[5,2]).'
y = 2×5
1 3 5 7 9 2 4 6 8 10

추가 답변 (2개)

Steven Lord
Steven Lord 2023년 4월 28일
x = [1, 5, 9, 4, 8; 3, 7, 2, 6, 10]
x = 2×5
1 5 9 4 8 3 7 2 6 10
y = reshape(x(:), flip(size(x))).'
y = 2×5
1 3 5 7 9 2 4 6 8 10
For comparison:
expected =[1, 3, 5, 7, 9 ; 2, 4, 6, 8, 10]
expected = 2×5
1 3 5 7 9 2 4 6 8 10

Kevin Holly
Kevin Holly 2023년 4월 28일
x = [1, 5, 9, 4, 8; 3, 7, 2, 6, 10]
x = 2×5
1 5 9 4 8 3 7 2 6 10
x2 = reshape(sort(reshape(x,1,[])),size(x,1),size(x,2))
x2 = 2×5
1 3 5 7 9 2 4 6 8 10

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by