【问题标题】:matlab: generating function output variable with GUI inputmatlab:使用GUI输入生成函数输出变量
【发布时间】:2016-04-06 08:55:54
【问题描述】:

我维护的一个软件包的功能之一是将用户对产品的简写名称解析为它的全名。在返回用户输入之前,该软件会尝试 2 种方法来自动执行此操作。如果自动尝试失败,则要求用户匹配表。

GUI 部分相当大,所以在它自己的子功能中维护。子函数将只返回idx 或索引变量。我很难让 matlab 足够“耐心”等待 GUI 指定 idx。

以下是 cmets 代码的重要部分:

function [ idx ] = mnmhelper( modeldb )
%mnmhelper makes a UI table for the user to manually select the correct
%model

%% uitable generation

f = figure('UserData',1); %userdata will be the selection;
t = uitable('Parent',f,...
    'Data',modeldb.Model,...
    'CellSelectionCallback',@select_callback);
b = uicontrol('Parent', f,...
    'Style','pushbutton',...
    'String','Commit Model Name',...
    'Callback',@button_callback);

%% callbacks - note that these are nested in the parent fnc

    function select_callback(hObject , eventdata)
        %hObject - handle to uitable
        %eventdata - currently selected table indexes

        f.UserData = eventdata.Indices; % pass selection as userdata array: [row,col]
    end

    function button_callback(hObject,eventdata,selection)
        idx = f.UserData(1);
        close(f);
        figclosed = 1; %see additional notes below code on this line
    end
end

问题是 matlab 会报错 idx 没有定义,因为它没有等待这个数字被使用。

我尝试添加该部分:

%% strongarm matlab into waiting for user to do this

figclosed = 0;
while figclosed < 1 %don't evaluate to command line until figure is finished
    % ... do nothing 
    % once this evaluates to ==1 and kicks out of this, idx is defined
end

在所有回调之后,但 matlab 将在 while 循环中等待并且图形不会生成。如何让 matlab 等待?

我需要一个 CreateFcn 来让 matlab 等待吗?

【问题讨论】:

    标签: matlab user-interface scope output nested-function


    【解决方案1】:

    uiwait 函数就是为了这个目的而存在的。只需调用uiwait(f) 让matlab 等待GUI 图形终止。

    参见文档:uiwait。

    【讨论】:

      猜你喜欢
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多