フィルターのクリア

classify array elements without so many if statement

2 ビュー (過去 30 日間)
zilai si
zilai si 2019 年 10 月 15 日
回答済み: Andrei Bobrov 2019 年 10 月 15 日
hello,everyone
Now i have an array A with double element between 0 to 8 ,now i want to sort them with interval length 0.5 ,i.e.
if A(i)<0.5
A(i) = 1;
else
if A(i)<1
A(i) = 2;
else
if A(i)<1.5
A(i) = 3;
else ...
But this is too lengthy and stupid...i wonder if there are any better ways to handle it.

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 10 月 15 日
out = discretize(A,0:.5:8)

その他の回答 (1 件)

Mir Amid Hashemi
Mir Amid Hashemi 2019 年 10 月 15 日
Use the discretize function
https://uk.mathworks.com/help/matlab/ref/double.discretize.html

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by