# how to get/extract x,y values from scatter function

조회 수: 14(최근 30일)
SatyaPrakash Gupta 2020년 3월 4일
댓글: SatyaPrakash Gupta 2020년 3월 6일
Hi,
I am currently plotting the X,Y coordinates using scatter function as below.
scatter(x(:,1),x(:,2),[],x(:,3),'filled')
I would like to get the x,y value which is being plotted with different colors, could you please do help me out here.
thank you.

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

### 채택된 답변

You need to apply thresholding to the 3rd column of the x variable upto blue colour as it is normalized colour. If you apply colourbar to the plot you can get idea how to choose threshold value
Demo:
>> x = rand(10, 2); % X, Y data
>> x(:, 3) = 1:10; % colour data where 1 indicates complete blue, 2 - somewhat diluted colour so it is normalized
>> ax = scatter(x(:,1),x(:,2),[],x(:,3),'filled');colorbar;
If you see the colorbar is the axes upto 5 level values are blue as you require, so get the values using CData properties of ax
>> x_values = ax.XData(ax.CData <5);
>> y_values = ax.YData(ax.CData <5);
Hope you get my point
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
SatyaPrakash Gupta 2020년 3월 6일
I think adding colorbar to the code will help to determine the range of the color , therefore it is a good idea to add colorbar
if there is a for loop for 6000 times and the 3rd element keeps changing , as soon as the loop is finished , then we can get the total limit /range of the colorbar , please do correct me if my udnerstanding is wrong ?
Also i would like to define the threshold between -10 to 10 , how can i do it because the code provided by you takes only one comparision ?

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

### 추가 답변(1개)

darova 2020년 3월 4일
Use handle
h = scatter(..)
get(h,'xdata')
##### 댓글 수: 1표시숨기기 없음
SatyaPrakash Gupta 2020년 3월 5일
with the above suggestion , i think the value will be the same as compared the input provided to the scatter.
I want to extract/get the value of X,Y which has being plotted with different colors like for example.
when the scatter color is blue, i want to get all the X Y coordinates of blue color similarly for Geen, Yellow

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

R2016b

### Community Treasure Hunt

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

Start Hunting!

Translated by