0
我維護的一個軟件包的功能之一是將用戶的產品縮寫名稱解析爲其全名。在回到用戶輸入之前,軟件會自動嘗試2種方法來自動完成此操作。如果自動嘗試失敗,則請求用戶與表匹配。matlab:使用GUI輸入生成函數輸出變量
GUI部分非常大,所以它保留在它自己的子功能中。該子功能將只返回idx
或索引變量。我有困難與matlab是「耐心」足以等待GUI指定idx。
下面是評論代碼的重要位:
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
f使matlab等待什麼?