Reversing an array within smaller subsets

조회 수: 12 (최근 30일)
Murtaza Mohammadi
Murtaza Mohammadi 2022년 11월 15일
댓글: Murtaza Mohammadi 2022년 11월 15일
Hello
I have a long array with 60 datapoints, say A = [1 2 3 4.....58 59 60]. I want to reverse in a subgroup of 5 elements, i.e. B = [5 4 3 2 1 10 9 8 7 6 15 14 13 12 11........60 59 58 57 56]. In fact a general solution can be handy, where an array with M elemnts need to flipped in N sized subsets.
Thank you
  댓글 수: 2
Murtaza Mohammadi
Murtaza Mohammadi 2022년 11월 15일
I am tempted to reshape matrix A into smaller matrix and then reverse it, but I don't want to do that as I expect my matrix A to become multidimensional when I collect more data.
Matt J
Matt J 2022년 11월 15일
That shouldn't matter.

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

채택된 답변

Matt J
Matt J 2022년 11월 15일
A=1:60;
reshape( flipud(reshape(A,5,[])) ,1,[])
ans = 1×60
5 4 3 2 1 10 9 8 7 6 15 14 13 12 11 20 19 18 17 16 25 24 23 22 21 30 29 28 27 26

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by