Reputation: 511
The algorithms loads two images and displays it. The user has the option of clicking on either one of the images and dragging it across the screen. The objective is to give the user the ability to overlay the images.
There are two scripts 1)Main.m and 2)gui_class. Script Main.m contains the gui functions and callbacks. gui_class is designed to load the images and simulates the click that initiates the dragging function of the image.
Within classdef gui_class < handle
lies
properties (Access = private)
x = [];
y = [];
c1 = [];
r1 = [];
h = [];
w = [];
gui_h;
end
methods
%function - class constructor - creates and init's the gui
function this = gui_class
%make the gui handle and store it locally
this.gui_h = guihandles(Main);
%set the callback functions
set(this.gui_h.load_image ,'callback' ,@(src, event) load_image_Callback(this, src, event))
end
end
` methods (Access = private)
function this = load_image_Callback(this, src, event)
%code loads and displays images here
%trigger a mouse click
set(gcf,'windowbuttondownfcn',@(src, event) Mclicked(src, event));
end
function Mclicked(this, src, event)
% get the handles structure
set(gca,'units','pix') ;
mousePositionData = get(gca, 'CurrentPoint')
this.x = mousePositionData(1,1);
this.y = mousePositionData(1,2);
%...Perform task
end
I get an error message : Error while evaluating figure WindowButtonDownFcn-Undefined function within a matlab guide class Undefined function 'Mclicked' for input arguments of type 'double'.
Error in gui_class/load_image_Callback/@(src,event)Mclicked(src,event)
How does one correctly call up this function correctly? In addition to that question, why is this occurring? I stated in it in main.m as mentioned below:
function Mclicked(hObject, eventdata, handles)
Upvotes: 0
Views: 1822
Reputation: 8401
The function Mclicked
is a method bound to instances of gui_class
and expects such a class as it's first argument or to be called via dot-notation from an instance of the class. So either
set(gcf,'windowbuttondownfcn',@(src, event) Mclicked(this, src, event));
or
set(gcf,'windowbuttondownfcn',@(src, event) this.Mclicked(src, event));
will invoke the method.
Upvotes: 1