GUI setup for scatter plot, taking samples

4 Ansichten (letzte 30 Tage)
Amirali Kamalian
Amirali Kamalian am 14 Apr. 2019
Beantwortet: Walter Roberson am 14 Apr. 2019
I have a scatter plot which presents the second column versus the first column of a matrix, A i.e.
scatter(A(:,1),A(:,2),'filled');
When I look at the graph, I want to choose a specific point (x,y) and find out what is the row number (i) of matrix A where
A(i,1)=x , A(i,2)=y
In other words, to find out the row number of A to which the selected point corresponds to.
Any ideas?

Antworten (1)

Walter Roberson
Walter Roberson am 14 Apr. 2019
call datacursormode() and provide an UpdateFcn property for it. When the user click on the graph, the function will be called, and the event parameter (second parameter) of the function call will have a Position property which gives coordinates. You can use pdist2() or similar to find the distances of the cursor to each of the points in the scatter object, and then you can output the index of that object in the form of a cell array of character vectors; the text will be displayed in the data tip.

Community Treasure Hunt

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

Start Hunting!

Translated by