delete elements of a vector wich are not consecutive
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey,
I have a Vector with a lot of values, where i only need the elements 73 to 144. After that I have to skip the next 72 Elements so that the next ones i need are 217 to 288. This continues until the end, so that the mechanism is: get 72 Elements then skip 72 then get 72, and so on. Is it somehow possible to delete the elements not needed as described above ?
Thanks for help :)
댓글 수: 0
채택된 답변
Rik
2021년 7월 29일
You need some tricky indexing, but I believe this is what you need:
v=1:(72*6);
k=72;
ind=(k:(2*k):(numel(v)-k)) + (1:k).';
%show as matrix for demo purposes:
ind.'
ind=ind(:);%linearize to vector
ind(ind>numel(v))=[];%remove trailing indices
v2=v(ind);
추가 답변 (1개)
KSSV
2021년 7월 29일
MAke your indices.....and then extract....
Hint: Your indices are in Arithmetic Progression.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!