Removing large parts of an array

15 次查看(过去 30 天)
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 个评论
Stefan Ganescu
Stefan Ganescu 2022-2-20
No, I have an 8000Hz signal in matlab and i wish to only show the first part so that it is easier to read

请先登录,再进行评论。

采纳的回答

Voss
Voss 2022-2-20
If it is a row or column vector:
x = randn(1,8000);
size(x)
ans = 1×2
1 8000
last_n_to_remove = 7000;
x(end-last_n_to_remove+1:end) = [];
size(x)
ans = 1×2
1 1000
  6 个评论
Stefan Ganescu
Stefan Ganescu 2022-2-20
If there is a way to show the first X elements, is there also a way to show the last X or elements between 2 values? Like if i wanted to show elements 3000 through 4000.
Voss
Voss 2022-2-20
编辑:Voss 2022-2-20
x = 1:8000;
% show the first 100 elements:
x(1:100)
ans = 1×100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
% show the last 100 elements:
x(end-99:end)
ans = 1×100
7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930
% show elements 3000 to 4000:
x(3000:4000)
ans = 1×1001
3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029
(when you do this on your computer, your command line will show the entire 100 or 1001 elements or whatever)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by