필터 지우기
필터 지우기

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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by