# How do I find the index of a datapointon a MATLAB plot?

조회 수: 66 (최근 30일)
S. Moore 2016년 8월 24일
댓글: Hassan Nikoo 2018년 8월 20일
With a very large dataset - assume 1 million [x,y] pairs or more - how do I find the index of an individual datapoint on a MATLAB plot?
Example: I use plot(x,y) and the plot appears. The plot is complicated but there are artifacts I can locate by eye much easier than writing a detection script. I zoom into the plot and locate the desired data artifact. I need to know the exact location (index) of the artifact. I zoom that individual datapoints are apparent, place a cursor on the datapoint of interest, but the cursor does not report the exact x(index) of the datapoint. Other than manually scrubbing through the data to find the index, how do I find the index by using the plot?
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
José-Luis 2016년 8월 25일
Why not use find() once you have the xy values?

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

### 답변 (2개)

D. Plotnick 2018년 7월 12일
This is my kludgy workaround: instead of
plot(x,y)
do
plot3(x,y,1:length(x));
view(0,90)
NOW use your data cursor, the z-value is the index of the point you are currently attached to. Voila!
I do wish this was an easier/more elegant change to the DataTip tool, since it would also be useful to use a standard plot command but with a third parameter variable that does not get plotted but does show up in the tooltip; useful for parametric equations. Something like my made-up 'plotParametric':
theta = linspace(0,2*pi,101); R = 1;
[x,y] = pol2cart(theta,R);
plotParametric(x,y,theta);
where now the tooltip will also display the parameter value theta at a given x-y point. Replace this with index, and it is your above problem.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Hassan Nikoo 2018년 8월 20일
This is GREAT. Great idea thanks.

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

Julian 2016년 8월 25일
Surely the approved method for this is to use a data cursor? I fear that it may respond slowly to navigation if you have a million points in the plot though.
You can try it with an elementary plot first to get the hang of it
plot(randn(100,1))
datacursormode % or you can use the icon in the figure window
shg
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
S. Moore 2016년 8월 25일
Furthermore, adjusting the data type in the console (i.e. "long") does not change the data display on the cursor.
Julian 2016년 8월 25일
I find that a problem too sometimes!
You could write your own DataTip callback functions to customize the display - but that's somewhat more work.
You can export the cursor to the workspace to discover its precise value - that is what I often do, although I think it's more of a faff than it needs to be.

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

### 카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by