0

I have formed a 2D matrix of 180X360. In fact, it is a LatXLong grid of 1°X1°. Each grid point has a value calculated according to my algorithm.

If I want to plot this LatXLong grid using any contour function, it is easy to do.

Now, what I need to do is to make this grid a clickable/ interactive contour plot in a way that when the user clicks anywhere on my grid plot, he gets an onscreen information or a further plot to be displayed specifically related to that grid point.

In short, I want to make a grid/contour plot in which all grid points are hyperlinks and linked to further background information.

Cape Code
  • 3,584
  • 3
  • 24
  • 45
Mushi
  • 367
  • 2
  • 4
  • 14
  • What have you tried so far? check similar questions as well, something like this http://stackoverflow.com/questions/14684577/matlab-how-to-get-mouse-click-coordinates or this one http://stackoverflow.com/questions/11233180/retrieving-x-and-y-values-from-matlab-plot – NKN Jan 21 '14 at 20:28
  • Thanks NKN.I am really interested in the second reference you mentioned. Can you please tell me how can get the coordinates as variables but not as writtne in the title of the figure or both at the same time. – Mushi Jan 23 '14 at 09:41

2 Answers2

1

check this answer: if you don't want to have the variable as title of the plot, you can modify the code as:

function mouseExample()
    h = plot(rand(10,1), 'o-');
    set(h, 'ButtonDownFcn',@buttonDownCallback)

    function out = buttonDownCallback(o,e)
        p = get(gca,'CurrentPoint');
        out = p(1,1:2);
        % title( sprintf('(%g,%g)',p) ) % --> no need this line anymore
    end
end

the information is saved in the P variable that you can use later.

Community
  • 1
  • 1
NKN
  • 6,482
  • 6
  • 36
  • 55
  • Thanks NKN once again. I have tried the above code but I am not getting any variable 'p' in my work space. Actually, I am using mouseExample as a function in another code and I want variable 'p' to be out from mouseExample on every click. I am sorry if I am not getting your point as I am not an expert in Matlab. Please help. – Mushi Jan 23 '14 at 13:58
  • Then you need your mouseExample returns the variable. do the same that I did in the buttonDownCallback function. – NKN Jan 23 '14 at 15:13
0

To get started, look into ginput and text. ginput will let you click on points in your plot and return the coordinates to some function that can generate information to be displayed in the current plot using text of by opening another figure.

You can use ginput in a loop to display multiple data points as you go:

for t = 1:10
    [x,y] = ginput(1);
    text(x,y,'some info');
end

I don't know of a way to remove the gird lines. NKN's solution might do that for you.

Molly
  • 13,240
  • 4
  • 44
  • 45
  • Thank Molly. You reply is really helpful. But there is a couple of things I was looking for which I am not getting with 'ginput'. (1) I would like to display the coordinates right after the user input (single input) for unlimited times. In the current implementation of ginput, multiple user inputs are saved in a two column matrix and then user has to press enter to get the values of the variables to be used afterwards. Also, pressing enter terminates the function which is not desirable. (2) When mouse moves on the figure, there are two grid lines moving with the cursor, can I remove them? – Mushi Jan 23 '14 at 10:08