两个不同文件中的两个图 - 如何从第二个图运行第一个图?

发布于 2024-10-06 08:48:54 字数 93 浏览 0 评论 0原文

我在两个不同的文件中有两个无花果。 通过单击第一个图上的按钮,我想显示第二个图......如何做到这一点?是否可以?

如果是,那么两个数字之间如何交换数据?

I have two figs in two different files.
By clicking a button on first fig I want to show the second one... how to do this? is it possible?

If YES than how to exchange with data between two figures?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰つ倒转 2024-10-13 08:48:54

有多种方法可以在 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

将上述代码保存到 m 文件后,您可以通过键入 gui_one 创建第一个 GUI。您将看到一个带有可编辑文本框和按钮的小图形窗口。如果您在文本框中输入内容,然后点击按钮,旁边就会出现第二个 GUI。第二个 GUI 使用从第一个 GUI 传递给它的可编辑文本框的句柄来获取文本字符串、显示它并清除第一个 GUI 中的字符串。

这只是一个简单的例子。有关在 MATLAB 中进行 GUI 编程的更多信息,请查看 MathWorks 在线文档< /a> 以及这个问题<的答案中的链接< /a>.

There are a number of ways to share data among GUIs. In general, you need to somehow make the graphics handle(s) from one GUI available to the other GUI so it can get/set certain object properties. Here's a very simple example that involves one GUI creating another and passing it an object handle:

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

After saving the above code to an m-file, you can create the first GUI by typing gui_one. You will see a small figure window with an editable text box and a button. If you type something in the text box, then hit the button, a second GUI will appear next to it. This second GUI uses the handle to the editable text box that is passed to it from the first GUI to get the text string, display it, and clear the string from the first GUI.

This is just a simple example. For more information on programming GUIs in MATLAB, take a look at the MathWorks online documentation as well as the links in the answers to this SO question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文