![]() |
两个不同文件中的两个数字-如何从第二个文件中运行第一个无花果?
我在两个不同的文件中有两个无花果。通过单击第一个无花果上的按钮,我想显示第二个无花果...该怎么做?可能吗?
如果是,那么如何在两个数字之间交换数据? [B]回答:[/B] 有多种[URL="http://www.mathworks.com/help/techdoc/creating_guis/f13-998449.html"]在GUI之间共享数据[/URL]的方法。通常,您需要以某种方式使一个GUI的图形句柄可用于另一GUI,以便它可以获取/设置某些对象属性。这是一个非常简单的示例,涉及一个GUI创建另一个GUI并向其传递对象句柄: function gui_one hFigure = figure('Pos',[200 200 120 70],... %# Make a new figure 'MenuBar','none'); hEdit = uicontrol('Style','edit',... %# Make an editable text box 'Parent',hFigure,... 'Pos',[10 45 100 15]); hButton = uicontrol('Style','push',... %# Make a push button 'Parent',hFigure,... 'Pos',[10 10 100 25],... 'String','Open new figure',... 'Callback',@open_gui_two); %#---Nested functions below--- function open_gui_two(hObject,eventData) gui_two(hEdit); %# Pass handle of editable text box to gui_two end end %#---Subfunctions below--- function gui_two(hEdit) displayStr = get(hEdit,'String'); %# Get the editable text from gui_one set(hEdit,'String',''); %# Clear the editable text from gui_one hFigure = figure('Pos',[400 200 120 70],... %# Make a new figure 'MenuBar','none'); hText = uicontrol('Style','text',... %# Make a static text box 'Parent',hFigure,... 'Pos',[10 27 100 15],... 'String',displayStr); end 将上面的代码保存到m文件后,您可以通过键入gui_one创建第一个GUI。您将看到一个小的图形窗口,其中包含可编辑的文本框和一个按钮。如果在文本框中键入内容,然后单击按钮,第二个GUI将出现在其旁边。第二个GUI使用从第一个GUI传递给它的可编辑文本框的句柄来获取文本字符串,显示它,并从第一个GUI清除该字符串。 这只是一个简单的例子。有关在MATLAB中对GUI进行编程的更多信息,请查看[URL="http://www.mathworks.com/help/techdoc/creating_guis/bqz79mu.html"]MathWorks在线文档[/URL]以及[URL="https://stackoverflow.com/questions/1115703/how-can-i-program-a-gui-in-matlab"]该SO问题[/URL]的答案中的链接。 [url=https://stackoverflow.com/questions/4363996]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:09。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.