And*_*mig 0 matlab exchange-server function figures
我在两个不同的文件中有两个无花果.通过点击第一个图上的按钮我想显示第二个...如何做到这一点?可能吗?
如果是,那么如何与两个数字之间的数据交换?
有许多方法可以在GUI之间共享数据.通常,您需要以某种方式使图形句柄从一个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
Run Code Online (Sandbox Code Playgroud)
将上述代码保存到m文件后,您可以通过键入来创建第一个GUI gui_one.您将看到一个带有可编辑文本框和按钮的小图窗口.如果您在文本框中键入内容,然后点击按钮,它旁边会出现第二个GUI.第二个GUI使用可编辑文本框的句柄,该文本框从第一个GUI传递给它,以获取文本字符串,显示它,并从第一个GUI中清除字符串.
这只是一个简单的例子.有关在MATLAB中编程GUI的更多信息,请查看MathWorks在线文档以及此SO问题的答案中的链接.