2017-02-25 168 views
0

算法加載兩個圖像並顯示它。用戶可以選擇其中一個圖像並將其拖過屏幕。目標是讓用戶能夠覆蓋圖像。評估圖中的錯誤WindowButtonDownFcn-未定義的函數在MATLAB指南類中

有兩個腳本1)Main.m和2)gui_class。腳本Main.m包含gui函數和回調。 gui_class用於加載圖像並模擬啓動圖像拖動功能的點擊。

classdef gui_class < handle 在於

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 

我得到一個錯誤信息:錯誤而MATLAB指導課 未定義功能「Mclicked」類型「雙」的輸入參數範圍內評估數字WindowButtonDownFcn-未定義功能。在gui_class/load_image_Callback/@(SRC,事件)Mclicked(SRC,事件)

錯誤

怎樣一個人準確地正確地調用這個函數呢?除了這個問題之外,爲什麼會發生這種情況呢? 我在它的main.m下面說明如所提到的:

function Mclicked(hObject, eventdata, handles) 

回答

1

功能Mclicked是綁定到的gui_class實例的方法,我們期望,因爲它的第一個參數或從一個經由點表示法稱爲這樣的類類的實例。因此,無論

set(gcf,'windowbuttondownfcn',@(src, event) Mclicked(this, src, event)); 

set(gcf,'windowbuttondownfcn',@(src, event) this.Mclicked(src, event)); 

將調用方法。

相關問題