delete elements of a vector wich are not consecutive
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fabian Heinzl
am 29 Jul. 2021
Kommentiert: Fabian Heinzl
am 29 Jul. 2021
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 Kommentare
Akzeptierte Antwort
Rik
am 29 Jul. 2021
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);
2 Kommentare
Weitere Antworten (1)
KSSV
am 29 Jul. 2021
MAke your indices.....and then extract....
Hint: Your indices are in Arithmetic Progression.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!