delete elements of a vector wich are not consecutive
3 ビュー (過去 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!