Removing large parts of an array
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stefan Ganescu
el 20 de Feb. de 2022
I have an array that has around 8000 elements. I wish to delete the last 7000 in a simple way, so that I am left with an array that has just the first 1000. Is there any way to do this?
2 comentarios
Respuesta aceptada
Voss
el 20 de Feb. de 2022
If it is a row or column vector:
x = randn(1,8000);
size(x)
last_n_to_remove = 7000;
x(end-last_n_to_remove+1:end) = [];
size(x)
6 comentarios
Voss
el 20 de Feb. de 2022
Editada: Voss
el 20 de Feb. de 2022
x = 1:8000;
% show the first 100 elements:
x(1:100)
% show the last 100 elements:
x(end-99:end)
% show elements 3000 to 4000:
x(3000:4000)
(when you do this on your computer, your command line will show the entire 100 or 1001 elements or whatever)
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays 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!