extract data from a 1D vector with a pattern

I have a 1D vector A=[1:1000]. I would like to start from the first elemnt of A and automatcially extract every first 16 elemnts but exclude the next 8 elements, and continue to end. In the end I have two vectors A1 (has every chunks of 16 elemnets) and A2 (every other chunk of 8 elemnts). In other words, A1 and A2 should include the follwing elemnts of vector A:
A1=[A(1:16), A(25:40), A(49:64), etc]
A2=[A(17:24), A(41:48), A(65:72), etc]

 채택된 답변

Yongjian Feng
Yongjian Feng 2021년 7월 22일

0 개 추천

Do it in a loop. Loop through 1 to 1000. Append elements to A1 and A2 inside the loop.

댓글 수: 2

Try this:
A = [1:1000];
A1 = [];
A2 = [];
i = 1;
while i < length(A)
A1 = [A1 A(i:i+15)];
A2 = [A2 A(i+16:min(i+23, 1000))];
i = i+24;
end
H R
H R 2021년 7월 25일
thanks

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

태그

질문:

H R
2021년 7월 22일

댓글:

H R
2021년 7월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by