I have some points like this:
matrix = rand(6, 4)
0.8147 0.2785 0.9572 0.7922
0.9058 0.5469 0.4854 0.9595
0.1270 0.9575 0.8003 0.6557
0.9134 0.9649 0.1419 0.0357
0.6324 0.1576 0.4218 0.8491
0.0975 0.9706 0.9157 0.9340
the first two columns are x and y values which get plotted as points via
plot(matrix(:, 1), matrix(:, 2), '*r'
Now what I want to work out is the following:
Whenever I click on a certain point in the plot, I want the information out of column 3 and 4 being displayed as text just right of the point in a box, e.g. with some text, e.g.
information 1: VALUE_COL3, information 2: VALUE_COL4
. How to achieve that? I thought of the ButtonDownFcn
attribute and than check out the clicked point and match it. But is there any easier way to do it?
Thanks!
While Sam's method is probably the correct solution here, I'd like to offer another one (although it is more of a 'hack' than a proper solution).
You can attach context menus to handle graphics objects. These menus can display multiple selections and even let your script respond to user selections. Take a look at the following example:
x = [1:10];
y = x.^2;
plot(x,y); hold on;
h = plot(x(5), y(5),'ro'); %% save the handle to the point we want to annotate
hcmenu = uicontextmenu;
item1 = uimenu(hcmenu, 'Label', 'info 1');
item2 = uimenu(hcmenu, 'Label', 'info 2');
item3 = uimenu(hcmenu, 'Label', 'info 2');
set(h, 'uicontextmenu', hcmenu);
When you right click on the 'o' point, you get the context menu:
More information can be found at the Mathwork's site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With