How to reach data stored in handles in a ButtownFcn?

handles, matlab, matlab-figure, matlab-guide, user-interface

Solution

Try this

`set(imageHandle,'ButtonDownFcn',{@ImageClickCallback,handles};`

Also in your function ImageClickCallback you need to add a category for handles as so:

`function ImageClickCallback(objectHandle, eventData, handles)`

Problem

I am trying to compare the click-obtained coordinates with a loaded matrix MT. I wrote a "loadMT" function to load the matrix MT, stored it into handles, and when it's finished it gives this(which I believe is a sign that MT has been stored in handles) ``` figure1: 173.0090 y_lbl: 11.0092 lbl_last_action: 10.0092 AverageModulus: 9.0092 axes1: 4.0092 slider: 3.0092 LoadMT: 0.0092 LoadImage: 174.0090 output: 173.0090 frameName: [599x1 struct] pathname: [1x43 char] no_frame: 599 MT: [4318x7 double] currentframe: 101 ``` Mouse click coordinate was obtained in a way recommended by this post MATLAB how to get mouse click coordinates. The core code is ``` imageHandle = imshow(imObj); set(imageHandle,'ButtonDownFcn',@ImageClickCallback); function ImageClickCallback ( objectHandle , eventData ) MT=handles.MT; axesHandle = get(objectHandle,'Parent'); coordinates = get(axesHandle,'CurrentPoint'); coordinates = coordinates(1,1:2); ``` And it has worked and I have got the coordinate.(without the MT=handles.MT line) However,when I click the image, it gives this error, means I failed to extract MT from the handles ``` Undefined variable "handles" or class "handles.MT". Error in GUI>ImageClickCallback (line 159) MT=handles.MT; ``` How may I pass the MT from handles to a local variables here? My searching results really confuse me. Thanks in advance

Original source

Related problems