Matlab实例学习--------不同界面的数据传递(多窗口编程)(实例)
来源:互联网 发布:联想笔记本安装mac os 编辑:程序博客网 时间:2024/05/29 16:53
实现功能为:两个窗口,一个主窗口一个子窗口。主窗口中有文本框和按钮,文本框用来显示子窗口中按钮的点击次数,按钮用来打开子窗口。 子窗口中包含文本框和两个按钮,文本框显示按钮点击次数,第一个按钮用来增加点击次数,第二个按钮用来返回主窗口。
实现步骤:
(1)创建两个GUI界面,分别为主窗口和子窗口,设置好相关属性和Tag等信息:
(2)编写主程序的回调函数:(主要是添加了按钮的响应函数)
function varargout = main(varargin)% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @main_OpeningFcn, ... 'gui_OutputFcn', @main_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before main is made visible.function main_OpeningFcn(hObject, eventdata, handles, varargin)% Choose default command line output for mainhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes main wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = main_OutputFcn(hObject, eventdata, handles) % Get default command line output from handles structurevarargout{1} = handles.output;% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)set(handles.figure1,'Visible','off');%将主窗口隐藏times=child(handles.figure1);%调用显示子窗口并接收子窗口的返回参数set(handles.text1,'String',num2str(times));%将文本设置为从子窗口接收过来的按钮点击次数
(3)编写子窗口的回调函数:
function varargout = child(varargin)% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @child_OpeningFcn, ... 'gui_OutputFcn', @child_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before child is made visible.function child_OpeningFcn(hObject, eventdata, handles, varargin)% Choose default command line output for childhandles.output = hObject;global count;%定义全局变量用来统计按钮点击次数count=0;%初始化main=varargin{1};%获取主窗口传递过来的参数handles.mainhandles=guihandles(main);%将主窗口传递过来的参数添加到handles结构体中% Update handles structureguidata(hObject, handles);%更新handles结构体% UIWAIT makes child wait for user response (see UIRESUME)uiwait(handles.figure1);%设置等待,等待用户进行操作% --- Outputs from this function are returned to the command line.function varargout = child_OutputFcn(hObject, eventdata, handles) % Get default command line output from handles structureglobal count;varargout{1} = count;%输出返回参数,返回按钮点击次数% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)global count;count=count+1;%按钮点击次数增加set(handles.text1,'String',num2str(count));%设置文本为点击次数% guidata(hObject, handles);%更新% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)set(handles.mainhandles.figure1,'Visible','on');%将主窗口显示出来uiresume(handles.figure1);%用户操作完成closereq%关闭子窗口
(4)程序运行结果
1 0
- Matlab实例学习--------不同界面的数据传递(多窗口编程)(实例)
- Matlab实例学习----数据传递
- 做一个实例,搞定MATLAB界面编程
- 【Matlab学习笔记】【编程实例】一(将两幅图像调整为相同的尺寸大小)
- MATLAB GUI界面之间的数据传递
- Matlab GUI 界面间数据的传递
- SpringMVC(5)传递JSON数据实例
- Qt5--多窗口编程实例
- Matlab实例学习------多项式和非多项式曲线拟合(实例)
- C#控制台基础 自定义类不同实例之间的赋值(引用传递的一个示例)
- matlab学习笔记(十五)---综合实例
- iphone 使用委托(delegate)在不同的窗口之间传递数据
- 使用委托(delegate)在不同的窗口之间传递数据
- iphone 使用委托(delegate)在不同的窗口之间传递数据
- 使用委托(delegate)在不同的窗口之间传递数据
- iphone 使用委托(delegate)在不同的窗口之间传递数据
- iphone 使用委托(delegate)在不同的窗口之间传递数据-转
- iphone 使用委托(delegate)在不同的窗口之间传递数据
- 如何查看自己运行ubuntu是32位还是64位
- html标签
- The Recode of the sat-problem
- 第三只眼看SpringSide-一个极富魅力的偶像团队
- php借助linux实现多线程1
- Matlab实例学习--------不同界面的数据传递(多窗口编程)(实例)
- 集群环境下防止并发的一种实现( Spring Quartz 集群思路)
- getCurrentSession 与 openSession() 的区别
- 11 绑定服务 本应用程序内
- 【ThinkPHP学习】volist标签使用
- Activity生命周期
- 周期串
- java中的八种基本数据类型
- [外语] R.I.P.