Removing large parts of an array

15 ビュー (過去 30 日間)
Stefan Ganescu
Stefan Ganescu 2022 年 2 月 20 日
編集済み: Voss 2022 年 2 月 20 日
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 件のコメント
Rik
Rik 2022 年 2 月 20 日
Is this homework?
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by