how to create a graphic-table point correspondence

1 回表示 (過去 30 日間)
laura bagnale
laura bagnale 2021 年 9 月 7 日
回答済み: Srijith Kasaragod 2021 年 10 月 29 日
Hello everyone,
I hope someone could help me with the following problem.
I have a set of points with (x,y) coordinates. I plotted them in a scatter graph. I would like to create a relation between points on the graph and those in the table, so that when I click one point on the graph, the corresponding point (x,y coordinates) in the table is highlighted.
Is it possible to do it?
Below, my code:
%quadratic curve
t = @(x,y) a.*x.^2 + b.*x.*y + c.*x + d.*y.^2 + e.*y + f
a = -0.0075
b = -0.1197
c = -1.6263
d = 0.0898
e = 1.1847
f = 0.2420
zhandle1 = fcontour(t)
zhandle=fcontour(t, [0 1], 'LevelList', 0)
hold off
M = zhandle.ContourMatrix
M1 = transpose(M)
T = array2table(M1, 'VariableNames',{'Xnorm','Ynorm'})
T.Variables = round(T.Variables,3);
T(1,:) = []
x1 = M(1,(2:122))
y1 = M(2,(2:122))
scatter(x1,y1)
In other words,
When I click on one random point in the graph I can see the coordinates x, y. Could I extract or to note these coordinates, corresponding to the point choosed on the graph, from the table?
Thank you very much in advance for you time and help.
Regards
Laura

回答 (1 件)

Srijith Kasaragod
Srijith Kasaragod 2021 年 10 月 29 日
Hi Laura,
You can use 'uitable' function to add a table into the figure and position it below the scatter plot using 'Position' property. Populate your table from workspace into the figure by assigning 'Data' field of uitable. Then using 'datacursormode' and 'getCursorInfo' functions, you can extract the value being clicked on the plot and perform a search on the uitable to identify and highlight the row corresponding to the point.
Refer this question to know how to extract user click from the plot. Additionally, refer this question to know how to programmatically scroll and select a row from uitable.
Hope this helps.

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by