classify array elements without so many if statement

1 Ansicht (letzte 30 Tage)
zilai si
zilai si am 15 Okt. 2019
Beantwortet: Andrei Bobrov am 15 Okt. 2019
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.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 15 Okt. 2019
out = discretize(A,0:.5:8)

Weitere Antworten (1)

Mir Amid Hashemi
Mir Amid Hashemi am 15 Okt. 2019
Use the discretize function
https://uk.mathworks.com/help/matlab/ref/double.discretize.html

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by