在gui的matlab之间传递数据 [英] Pass data between gui's matlab

查看:462
本文介绍了在gui的matlab之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个gui,一个是主gui,另一个是子gui.在主gui的打开功能中,我使用了open('subgui.fig');打开子GUI. Main由5个编辑框和1个按钮组成.按下按钮后,应将这5个编辑框中的数据传递给子GUI,并关闭主GUI.请任何人帮助我做到这一点.

I have two gui's one is main gui and other is sub gui. In opening function of main gui i used open('subgui.fig'); to open sub gui. Main consists of 5 edit box and one pushbutton. After pressing pushbutton the data in those 5 edit boxes should be passed to sub gui and main gui should close. Please any one help me to do this.

推荐答案

让我们以one editbox and one pusbutton in main GUIone editbox in sub GUI的简单情况为例,它们将从主GUI的编辑框中获取值.可以轻松地将其扩展到所需的多个编辑框.数据存储和检索的基本介质将是全局结构data1.

Let us take a simple case of one editbox and one pusbutton in main GUI and one editbox in sub GUI that will get value from the editbox in main GUI. One can easily extend this to as many editboxes as needed. The basic medium of data storage and retrieval would be a global structure data1.

为了理解代码,让我们采取以下假设-

For the sake of understanding the codes, let us take the following assumptions -

  • 主GUI被命名为main_gui.m,因此具有关联的 main_gui.fig来自GUIDE.主GUI的图形具有标签main_gui_figure.
  • 子GUI被命名为sub_gui.m,因此具有关联的sub_gui.fig 来自GUIDE.
  • Main GUI is named as main_gui.m and thus has an associated main_gui.fig from GUIDE. Main GUI's figure has the tag main_gui_figure.
  • Sub GUI is named as sub_gui.m and thus has an associated sub_gui.fig from GUIDE.

要在main_gui.m中进行的编辑

在编辑框的回调中,添加此内容-

Inside editbox's callback, add this -

global data1;

%%// Field in data1 to store the string in editbox from main GUI
data1.main_gui.edit1val = get(hObject,'String'); 

在按钮的回调中,在返回之前添加此内容-

Inside the pushbutton's callback, add this right before it's return -

global data1;
sub_gui;
delete(handles.main_gui_figure);

要在sub_gui.m中进行的编辑

在sub_gui_OpeningFcn内,添加此-

Inside sub_gui_OpeningFcn, add this -

global data1;
set(handles.edit1,'String',data1.main_gui.edit1val);%%// Tag of editbox in sub-gui is edit1

希望这对您有用!让我们知道!

Hope this works out for you! Let us know!

这篇关于在gui的matlab之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆