I want to extract data point from a part of a plot. If I plot my data I can see the data points are distributed in groups or cluster. I want to extract one such cluster for further processing.
For example, lets look at the following code.
x=[1,10,20,3,11,23,4,12,13,13,24]+rand(1,11);
y=[2,7,21,1,8,24,3,9,8,10,22]+rand(1,11);
plot(x,y,'ro')
Now suppose I want to extract the data points of the middle group for further processing. Is it possible in matlab, if yes how can I do it?

 채택된 답변

Apurba Paul
Apurba Paul 2022년 8월 8일

0 개 추천

I have figured out a way. You can actually select data direclty from plot using Brush/Select data tools, whcich can be accessed through the top right corner of the current axis. You can then drag and select any part of the data, and then you can copy, delete or manipulate the data. See the figure bellow.
For more detail see the following link:

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 8월 6일

1 개 추천

Do they need to be extracted from the plot or can we use x and y instead?
Is the number of groups known? This code assumes that it is.
x=[1,10,20,3,11,23,4,12,13,13,24]+rand(1,11);
y=[2,7,21,1,8,24,3,9,8,10,22]+rand(1,11);
num_groups = 3;
%cluster them to figure out which ones belong together
[IDX, C] = kmeans([x(:), y(:)], num_groups);
%but which one is the "center" group? Find the center that
%is closest to the centroid of the data ?
D = pdist2(C, [mean(x(:)), mean(y(:))]);
[~, centeridx] = min(D);
%extract items that are in that center group
xc = x(IDX == centeridx);
yc = y(IDX == centeridx);
scatter(xc(:), yc(:), 'b+')
xlim([min(x)-1, max(x)+1])
ylim([min(y)-1, max(y)+1])

댓글 수: 1

Apurba Paul
Apurba Paul 2022년 8월 8일
@Walter Roberson, this seems a nice idea to use kmeans to find the cluster. But for this perticular workflow, it will be much easier for me if I can direcltly select the data from plot. Thankfully I have figured out a way. You can actually select data direclty from plot using Brush/Select data tools, whcich can be accessed through the top right corner of the current axis. You can then drag and select any part of the data, and then you can copy, delete or manipulate the data. See the figure bellow.
For more detail see the following link:

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 8월 6일

답변:

2022년 8월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by