【发布时间】: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