hello everyone. How to divide a group of points named data into two parts, dataA and dataB, as shown in the figure. Thank you very much.
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
Stephan
2021 年 6 月 2 日
編集済み: Stephan
2021 年 6 月 2 日
% divide data
idx = clusterdata(data,2);
dataA = data(idx==2,:);
dataB = data(idx==1,:);
% plot results
scatter(dataA(:,1),dataA(:,2))
hold on
scatter(dataB(:,1),dataB(:,2))
hold off
result is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/639780/image.png)
Note that this needs Statisitcs and Machine Learning Toolbox.
3 件のコメント
その他の回答 (1 件)
KSSV
2021 年 6 月 2 日
x = data(:,1) ;
y = data(:,2) ;
mx = mean(x) ; my = mean(y) ;
idx = y < my ;
x1 = x(idx) ; y1 = y(idx) ;
x2 = x(~idx) ; y2 = y(~idx) ;
plot(x,y,'.r')
hold on
plot(mx,my,'*b')
plot(x1,y1,'.b')
plot(x2,y2,'.g')
参考
カテゴリ
Help Center および File Exchange で Other Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!