Rearrangement of vector elements
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello everyone,
I have a vector that contains 1252459 elements and I need to rearrange these elements so that every 250th and 251nd element become the last elements of the vector. To be more clear, if the initial vector is
b=[1st element; 2nd element;...; 250th element; 251st element; ...; 500th element; 501st element;...;1252459th element]
it has to become
b=[1st element; 2nd element; ... (every element that should not be moved here) ... ; former 250th element; former 251st element; former 500th element; former 501st element; former 750th element ; former 751st element;...]
Thanks in advance.
댓글 수: 0
답변 (2개)
Jan
2021년 4월 8일
편집: Jan
2021년 4월 8일
Maybe you want:
b = rand(1252459, 1);
match = false(size(b));
match(1:249:end) = true;
match(2:249:end) = true;
c = b(match);
댓글 수: 2
Jan
2021년 4월 8일
Try it with some smaller data:
x = 11:20
m = false(size(x))
m([2,4,6]) = true
x(m)
m contains FALSE values except for the 2nd, 4th and 6th value, which are true. Using this vector as "logical index", only the elements are replied, which have a TRUE inside the index vector.
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!