4个简单的m文件来说明这四种方法
1. my_gui1.m 代码如下
function varargout = my_gui1( varargin )
if nargin == 0
figure;
uicontrol('str', '提取', 'cal', 'my_gui1(''get_data'', gcbo)' ) ;
str = 'hello!' ;
setappdata( gcf, 'mydata', str ) ;
else
feval( varargin{:}) ;
end
function get_data( h )
str = getappdata( gcf, 'mydata' ) ;
msgbox(str)
2. my_gui2.m 代码如下
function varargout = my_gui2( varargin )
if nargin == 0
figure ;
uicontrol('str', '提取', 'cal', 'my_gui2(''get_data'', gcbo)' ) ;
str = 'hello!' ;
handles = guidata( gcf ) ;
handles.MyData = str ;
guidata(gcf, handles ) ;
else
feval( varargin{:}) ;
end
function get_data( h )
handles = guidata(gcf) ;
str = handles.MyData;
msgbox(str)
3. my_gui3.m 代码如下
function varargout = my_gui3( varargin )
if nargin == 0
figure ;
uicontrol('str', '提取', 'cal', 'my_gui3(''get_data'', gcbo)' ) ;
str = 'hello!' ;
set( gcf, 'UserData', str ) ;
else
feval( varargin{:}) ;
end
function get_data( h )
str = get( gcf, 'UserData' ) ;
msgbox(str)
4. my_gui4.m 代码如下
function varargout = my_gui4( varargin )
if nargin == 0
figure ;
uicontrol('str', '提取', 'cal', 'my_gui4(''get_data'', gcbo)' ) ;
global str
str = 'hello!' ;
else
feval( varargin{:}) ;
end
function get_data( h )
global str
msgbox(str)
[此贴子已经被作者于2007-7-1 1:34:40编辑过]