Matlab GUI、グローバル変数、単一のフォーム内の関数間でデータを渡す



Matlab Gui Global Variables



(コード:2 global_data.m)

% Before the form is opened, the function global_data_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject% (1) first way % global times % times=0% guidata(hObject, handles) ) update data % (2) second way % handles.times = 0 % guidata (hObject, handles) % (3) third way % set(handles.add, 'UserData', 0) % Pass the data using the UserData property of the add button (handle). % guidata(hObject, handles)% (4) The fourth way setappdata(handles.figure1,'times',0) %Use setappdata function to set global variable guidata(hObject, handles)% add button callback function Function add_Callback(hObject, eventdata, handles)times=getappdata(handles.figure1,'times') % Get the value of the global variable times=times+1 setappdata(handles.figure1,'times',times) %Update global The value of the variable set(handles.disp, 'String', num2str(times)) % sets the display content of the disp text box