Displaying information about the data set by clicking on its plot and then show a value that is associated with the (x,y) point

12 次查看(过去 30 天)
Hello,
So, I have a GUI and I'll plot a figure in this GUI. Then I want the user to be able to click somewhere on the curve, and then the information about that point will show up. I followed what was said here: https://www.mathworks.com/matlabcentral/answers/11668-displaying-information-about-the-data-set-by-clicking-on-its-plot
But, also, I want, aside from showing the x and y coordinates, to show another information that's associated with each (x,y) point. Like a (x,y) point indicated the value of z. Is it possible?
For example:
x =
0.0960 0.2496 0.4032 0.5568 0.7104 0.8640
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
y =
0.0960 0.2496 0.4032 0.5568 0.7104 0.8640
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36
fh = figure;
plot(x(2,:), y(2,:)); hold on;
plot(x(3,:), y(3,:)); hold on;
plot(x(4,:), y(4,:)); hold on;
datacursormode on
dcm = datacursormode(gcf);
set(dcm,'UpdateFcn',@myupdatefcn)
function txt = myupdatefcn(trash,event)
pos = get(event,'Position');
dts = get(event.Target,'Tag');
txt = {dts,...
['x: ',num2str(pos(1))],...
['y:', num2str(pos(2))]};
I want to show x(1, ?) and y(1, ?) when the user clicks on a point in the curve.
Thank you all

采纳的回答

Matt J
Matt J 2020-1-17
编辑:Matt J 2020-1-17
....
set(dcm,'UpdateFcn',@(t,e) myupdatefcn(t,e,x,y) );
function txt = myupdatefcn(~,event,xdata,ydata)
pos = get(event,'Position');
dts = get(event.Target,'Tag');
[~,j]= find( xdata==pos(1) & ydata==pos(2) );
txt = {dts,...
['x: ',num2str(pos(1)),' x(1,?): ', num2str(xdata(1,j))],...
['y: ',num2str(pos(2)),' y(1,?): ', num2str(ydata(1,j))]};
end
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

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