# 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 view (last 30 days)
Wesley on 2 Jun 2021
Commented: Wesley on 2 Jun 2021
##### 1 CommentShowHide None
Wesley on 2 Jun 2021

Sign in to comment.

### Accepted Answer

Stephan on 2 Jun 2021
Edited: Stephan on 2 Jun 2021
% 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:
Note that this needs Statisitcs and Machine Learning Toolbox.
##### 3 CommentsShowHide 2 older comments
Wesley on 2 Jun 2021
It is very helpful to me. Thank you for your warm-hearted reply.

Sign in to comment.

### More Answers (1)

KSSV on 2 Jun 2021
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')
##### 1 CommentShowHide None
Wesley on 2 Jun 2021
Thank you for your warm-hearted reply.

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!