2014-02-26 1 views
2

다른 GUI (DistanceOrderGUI) 내에서 호출되는 matlab GUI (Compare2ImagesGUI)이 있으며 사용자와의 상호 작용을 기반으로 변수를 반환해야합니다.MATLAB GUI에서 다른 함수로 데이터 전달

function init(hObject,handles) 

imshow(handles.ima,'Parent',handles.axes1); 
handles.current = handles.a; 

% handles.ims=ims; handles.gt=gt; 
% handles.folderN=folderN; handles.name=dirnames{folderN}; 

% Update handles structure 
guidata(hObject, handles); 
:

function Compare2ImagesGUI_OpeningFcn(hObject, eventdata, handles, varargin) 
% This function has no output args, see OutputFcn. 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
% varargin command line arguments to Compare2ImagesGUI (see VARARGIN) 

% Choose default command line output for Compare2ImagesGUI 
%handles.output = hObject; 
a = varargin{2}.a; 
b = varargin{2}.b; 
handles.a = a; 
handles.b = b; 
handles.ima = varargin{2}.ims{a}; 
handles.imb = varargin{2}.ims{b}; 
init(hObject,handles); 

% UIWAIT makes Compare2ImagesGUI wait for user response (see UIRESUME) 
uiwait(hObject); 

이는 init 함수입니다 : 여기

a=1;b=2; 
handles.a = a; 
handles.b = b; 

result = Compare2ImagesGUI('DistanceOrderGUI', handles) 

그리고이 열릴 때 무엇을한다 : 여기

는 a를 Compare2ImagesGUI가 호출되는 방법의 조각입니다

사용자가 상호 작용을 마치면 버튼을 누르고 GUI 닫고 그 호출 함수에 값을 반환해야합니다 :이 코드는 그럼에도 불구하고 나는이 이상한 오류가 그것에 대해 무엇을해야하는지에 정말 우둔 오전 herehere을 발견 구조화하는 방법에 대한 지시를 따라

% --- Executes on button press in pushbutton3. 
function pushbutton3_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton3 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
figure1_CloseRequestFcn(hObject,handles); 

% --- Outputs from this function are returned to the command line. 
function varargout = Compare2ImagesGUI_OutputFcn(hObject, eventdata, handles) 
% varargout cell array for returning output args (see VARARGOUT); 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

% Get default command line output from handles structure 
varargout{1} = handles.current 

delete(handles.Compare2ImagesGUI); 


% --- Executes when user attempts to close figure1. 
function figure1_CloseRequestFcn(hObject, handles) 
% hObject handle to figure1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

if isequal(get(hObject,'waitstatus'),'waiting') 
    uiresume(hObject); 
else 
    delete(hObject); 
end 

:

Error using hg.uicontrol/get 
The name 'waitstatus' is not an accessible property for an instance of 
class 'uicontrol'. 

Error in Compare2ImagesGUI>figure1_CloseRequestFcn (line 127) 
if isequal(get(hObject,'waitstatus'),'waiting') 

Error in Compare2ImagesGUI>pushbutton3_Callback (line 118) 
figure1_CloseRequestFcn(hObject,handles); 

Error in gui_mainfcn (line 96) 
     feval(varargin{:}); 

Error in Compare2ImagesGUI (line 42) 
    gui_mainfcn(gui_State, varargin{:}); 

Error in 
@(hObject,eventdata)Compare2ImagesGUI('pushbutton3_Callback',hObject,eventdata,guidata(hObject)) 


Error using waitfor 
Error while evaluating uicontrol Callback 

줄 127은 function figure1_CloseRequestFcn(hObject, handles) 기능에 있습니다. 어떤 제안?

+0

해결책이 효과가 있었습니까? – chappjc

+0

네,'figure1_CloseRequestFcn'의 버전이 그것을 해결 했으므로 어떤 것이 작동하지 않았는지 궁금 할 것입니다. – chappjc

답변

1
보통 CloseRequestFcn 당신이 만든 uicontrol를 통해 호출되지

, 오히려 때

  • 하면 상단에 내장 된 그림 컨트롤 (예 : "X"상자를 사용하여 그림을 닫거나 그림 메뉴)
  • close은 무슨 일을한다는 것입니다 MATLAB

종료

  • 당신의 그림에 대해 호출은 자체 핸들 대신 그림의 핸들hObject에서 figure1_CloseRequestFcn으로 전달합니다. 문제는 'waitstatus' 속성이 figure에만 속합니다.

    해결 방법 pushbutton3_Callback을 수정하여 그림 핸들을 전달하거나 pushbutton3_Callback을 수정하여 그림 핸들 만 사용하십시오.

    % --- Executes when user attempts to close figure1. 
    function figure1_CloseRequestFcn(hObject, eventdata, handles) 
    % hObject handle to figure1 (see GCBO) 
    % eventdata reserved - to be defined in a future version of MATLAB 
    % handles structure with handles and user data (see GUIDATA) 
    
    hFig = ancestor(hObject,'Figure'); 
    if isequal(get(hFig,'waitstatus'),'waiting') 
        uiresume(hFig); 
    else 
        delete(hFig); 
    end 
    

    참고 : I 추가하며 사용자 코드에서 누락 될 듯 figure1_CloseRequestFcneventdata 인수, 예를 들어. 일반적으로 @(hObject,eventdata)guitest('figure1_CloseRequestFcn',hObject,eventdata,guidata(hObject))으로 정의됩니다.