Save data with different intervals?

조회 수: 6 (최근 30일)
riccardo favaro
riccardo favaro 2021년 8월 8일
편집: Yazan 2021년 8월 8일
I have an array of data and I need to discard the first 7 values, save 15 values and discard other 7 values and keep going until the end of the array.
What is the easiest way to do it? I've tried with a for loop but I don't know how to set the index.
Also, if i want to, let's say, add or subtract a points every 4 repetitions how could I do it? So after 4 times I discard 7 values and save the following 16 values.
Thanks in advance if someone will help me, I'm very stucked.
  댓글 수: 1
Yazan
Yazan 2021년 8월 8일
편집: Yazan 2021년 8월 8일
Below, j1 and j2 are the first and last indexes, respectively, of the data you need to save.
todiscard = 7;
tokeep = 15;
j1 = todiscard+1:tokeep:length(data)-tokeep;
j2 = j1 + tokeep-1;

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 8일
편집: Walter Roberson 2021년 8월 8일
temp = reshape(YourVector, 7+15, []);
to_save = reshape(temp(8:end,:), 1, []);
So after 4 times I discard 7 values and save the following 16 values.
temp = reshape(YourVector, 7+15+7+15+7+15+7+16, []);
temp([22*0+(1:7), 22*1+(1:7), 22*2+(1:7), 22*3+(1:7)],:) = [];
to_save = reshape(temp, 1, []);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by