delete elements of a vector wich are not consecutive
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fabian Heinzl
el 29 de Jul. de 2021
Comentada: Fabian Heinzl
el 29 de Jul. de 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 comentarios
Respuesta aceptada
Rik
el 29 de Jul. de 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 comentarios
Más respuestas (1)
KSSV
el 29 de Jul. de 2021
MAke your indices.....and then extract....
Hint: Your indices are in Arithmetic Progression.
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!