2013-12-16 1 views
1

GUIDE로 GUI를 만들었으므로 콜백에서 콜백을 호출 할 때 GUI 핸들을 업데이트하는 방법을 알 수 없습니다. 그래서 함수를 호출하는 기능의 예를 들어 내가 가진 모든는 다음과 같다 :콜백을 사용할 때 GUI 핸들 업데이트

function start_ss_Callback(hObject, eventdata, handles) 
% hObject handle to start_ss (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

% Hints: get(hObject,'String') returns contents of start_ss as text 
%  str2double(get(hObject,'String')) returns contents of start_ss as a double 
start_hh_Callback(hObject, eventdata, handles) 

start_hh_Callback에 나는 코드가 아래에 주어진하지만 난 guidata(hObject, handles)을 가지고 내 handles.plot_holds에 관계없이 사실을 업데이트하지 않습니다 있습니다. 내가 이것을 함수로 사용하고 있기 때문에 이것인가? 방금 start_hh_Callback을 거치지 않고 start_ss_Callback을 통하지 않으면 업데이트됩니다. 그러나 start_ss_Callback과 같은 콜백 내에서 사용하면 업데이트되지 않습니다.

제 질문이 명확히되기를 바랍니다. 설명이 필요한 경우 알려 주시기 바랍니다.

function start_hh_Callback(hObject, eventdata, handles) 
% hObject handle to start_hh (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

% Hints: get(hObject,'String') returns contents of start_hh as text 
%  str2double(get(hObject,'String')) returns contents of start_hh as a double 

axes(handles.axes1) 
if isempty(handles.plot_holds) 
    cla 
    plot_button_Callback(hObject, eventdata, handles) 
else 
    % in the event the time is changed after more than 1 plot is held then 
    % the additional plot times will be re evaluated for each parameter and 
    % the new indicies will take into affect. 
    myParams = get(handles.load_params_button,'string'); 
    mystartDD = str2num(get(handles.start_dd,'string')); 
    mystartHH = str2num(get(handles.start_hh,'string')); 
    mystartMM = str2num(get(handles.start_mm,'string')); 
    mystartSS = str2num(get(handles.start_ss,'string')); 

    myendDD = str2num(get(handles.end_dd,'string')); 
    myendHH = str2num(get(handles.end_hh,'string')); 
    myendMM = str2num(get(handles.end_mm,'string')); 
    myendSS = str2num(get(handles.end_ss,'string')); 

    startFromStart = (mystartDD)*60*60*24 + (mystartHH-handles.startHour)*60*60 ... 
     + (mystartMM-handles.startMinute)*60 + (mystartSS-handles.startSecond); 
    endFromStart = (myendDD)*60*60*24 + (myendHH-handles.startHour)*60*60 ... 
     + (myendMM-handles.startMinute)*60 + (myendSS-handles.startSecond); 

    iStart = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time > (startFromStart+handles.startTimeOffset),1); 
    iEnd = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time > (endFromStart+handles.startTimeOffset),1); 
    if isempty(iEnd) 
     iEnd = length(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time); 
    end 

    cla 
    hold off 

    plot(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time(iStart:iEnd),... 
     handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Data(iStart:iEnd)) 

    grid minor 
    box on 

    handles.plot_holds(1,3) = iStart; 
    handles.plot_holds(1,4) = iEnd; 

    if size(handles.plot_holds,1)>1 
     hold all 
     for ii = 2:size(handles.plot_holds) 
      iStart = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time > (startFromStart+handles.startTimeOffset),1); 
      iEnd = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time > (endFromStart+handles.startTimeOffset),1); 
      if isempty(iEnd) 
       iEnd = length(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time); 
      end 
      plot(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time(iStart:iEnd),... 
       handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Data(iStart:iEnd)) 
      handles.plot_holds(ii,3) = iStart; 
      handles.plot_holds(ii,4) = iEnd; 
     end 
    end 
end 

legend(handles.myLegends{1:length(handles.myLegends)}) 

guidata(hObject, handles); 
+0

내가 디버거 모드로 가서 내가 그들을 볼 수있는 handles.plot_holds 그것을 중지 할 때 한 가지 더이 hhcall이 끝나자 마자 hhcall이 끝나면 이전의 숫자로 돌아갑니다. – Niseonna

답변

3
당신은 어떤 핸들 - 수정 기능을 한 후, 다시 핸들을로드해야합니다

: 당신이 콜백의

% this modifies and writes the handles to the guidata 
start_hh_Callback(hObject, eventdata, handles); 
% now read back the updated value 
handles = guidata(hObject); 

은 또한 당신은 또한 handles 반환 값을 만들 수 있습니다. 보통 이것은 콜백으로 실제로 사용될 때 무시되며 "보통"함수로 사용될 때 guidata에서 다시 읽을 필요가 없습니다. 코드는 다음과 같을 수 있습니다 : 콜백와

handles = start_hh_Callback(hObject, eventdata, handles); 

가로 다시 정의 :

function [handles] = start_hh_Callback(hObject, eventdata, handles) 
... 
end 
+0

굉장한! 정말 고마워 .. 나는 전체 코드를 복사하여 붙여 넣어야 할 것 같았다. 나는 두 번째 제안을 사용했다. 첫번째 것은 나를 위해 아주 일하지 않았다. – Niseonna