Putting similar numbers into groups within an array
이전 댓글 표시
I have an array of numbers that looks something like follows. I want to group the array into subgroups where the numbers are all within 2 of each other. In this case, there would be 3 groups. Is there an easy way to do this? I need the method to be automated for work for arrays 100 entries long.
7340.1
7340.3
7340.6
7349.0
7349.4
7358.0
7358.1
7358.2
7358.7
% New groups would look like follows:
% Group 1
7340.1
7340.3
7340.6
% Group 2
7349.0
7349.4
% Group 3
7358.0
7358.1
7358.2
7358.7
채택된 답변
추가 답변 (1개)
Image Analyst
2017년 6월 19일
1 개 추천
댓글 수: 2
Alamgir M S M
2019년 3월 10일
This is my Data-
[705.7142857 705.7142857 173.4285714 84.71428571 232.5714286 232.5714286 114.2857143 55.14285714 25.57142857 74.85714286 35.42857143 15.71428571 5.857142857 5.857142857].
I want to group same data into 1 group. This is 14*1 matrix where it has 3 pairs(705.7142857 705.7142857, 232.5714286 232.5714286 & 5.857142857 5.857142857) of same value data. So, I want these 3 pairs into 3 groups and rest of them into other 8 groups.
Is there anybody who can help me to code this?
Image Analyst
2019년 3월 10일
Use unique() and setdiff(). On the remainder, use kmeans() to group into 8 groups. Should be easy. If you can't figure it out, let me know.
카테고리
도움말 센터 및 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!