フィルターのクリア

Selecting numbers ending in a specific digit from a matrix

9 ビュー (過去 30 日間)
Taylor Lovell
Taylor Lovell 2021 年 12 月 10 日
コメント済み: Stephen23 2021 年 12 月 10 日
Hello,
I am trying to write a code that will select numbers from a file that end specifically in the numbers 4 or 9. The numbers are randomly generated and there are 10,000 numbers so the code needs to be able to be applied to the entire file

採用された回答

Chunru
Chunru 2021 年 12 月 10 日
編集済み: Chunru 2021 年 12 月 10 日
% Assume the numbers are integers
x = randi([-2000,2000], 100, 1);
% The number end with 4 or 9
x1 = mod(abs(x), 10);
idx = x1==4 | x1==9;
x(idx)
ans = 18×1
39 989 -779 1909 -1874 -1794 1479 1194 1704 -369

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by