2016-09-14 1 views
0
%*********************************************************************% 
%     Name of the GUI is 'dummy'      % 
%*********************************************************************% 

%*********************************************************************% 
%  Initialize count to zero in the GUI opening function   % 
%*********************************************************************% 



function dummy_OpeningFcn(hObject, eventdata, handles, varargin) 

handles.count=0; 
set(handles.text1,'String',num2str(handles.count)); 
handles.output = hObject; 
guidata(hObject, handles); 


%******************************************************************************* 
% increase the count and update the static text box using pushbutton callback % 
%******************************************************************************% 

function pushbutton1_Callback(hObject, eventdata, handles) 

handles.count=handles.count+1; 
set(handles.text1,'String',num2str(handles.count)); 

上記のコードでは、変数handles.countは、GUIのオープニング機能では「0」、コールバックは、各クリックでカウントを増やし、静的テキストボックスの内容を更新すると想定されます。しかし、ボタンのコールバック関数で変数にアクセスするたびに変数handles.countが '0'になり、結果として静的テキストボックスの内容は常に '1'にな​​ります。MATLAB GUIの 'ハンドル'構造内の変数は、プッシュボタンコールバックで自動的にゼロになります

答えて

0

は私の愚かな、私はそれが問題を解決し

のカウントをインクリメントした後

guidata(hObject, handles); 

を使用するのを忘れ

関連する問題