Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Imagesc ButtonDownFcn problems in MATLAB, using custom toolbar action

$
0
0
Hi!

I'm trying to use the BUTTONDOWNFCN on an IMAGESC figure in MATLAB. I want to enable this function by clicking on a CUSTOM BUTTON i have created on the toolbar.

The buttondownfcn will call methods that will cause it to return the position of the pixel selected using the buttondownfcn, so that I can graph how that pixel changes through time.

NOTES:
- I am using GUIDE in matlab
- Imagesc is plotting a 3D matrix. I already have implemented code that allows me to travel through how the image changes through time, using a button created in GUIDE.

What I am struggling with, at the moment, is the ButtonDownFcn of the imagesc. I've read over and over on how to do this (through research on the internet), but I can't seem to get it to work.

Any help is appreciated.

Here is my code:

        % --------------------------------------------------------------------
    function ui_throughTime_ClickedCallback(hObject, eventdata, handles)
    % hObject handle to ui_throughTime (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)
    valS = get(handles.txt_zaxis,'string');
    display(valS);
    val = str2num(valS);
    d = handles.data;
    m = imagesc(d(:,:,val),'parent',handles.axis, 'HitTest', 'off','buttondownfcn',{@getPlace, handles});
    set(handles.axis,'buttondownfcn',{@getPlace, handles,m});
    
    function getPlace(hObject,handles,event_obj,place)
    % data = randn(120,160);
    % ax = axes;
    % imagesc(data,);
    if (gcf == place)
        pause(1);
        cursor = get(handles.axis,'CurrentPoint'); % get point
        % Get X and Y from point last clicked on the axes
        x = (cursor(1,1));
        y = (cursor(1,2));
        disp(['x = ' num2str(x) ' y = ' num2str(y)]);
    end

Thanks

Viewing all articles
Browse latest Browse all 19628

Trending Articles