classify array elements without so many if statement
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
更多回答(1 个)
Mir Amid Hashemi
2019-10-15
Use the discretize function
https://uk.mathworks.com/help/matlab/ref/double.discretize.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!