如何从GUIDE GUI而不是图形句柄返回自定义值?
value = myGui();
答案 0 :(得分:0)
创建所需的GUI(用户控件,输入字段,处理逻辑等)
修改默认GUIDE生成的代码,如下所示(故意遗漏任何不需要修改的内容)。
uiwait
作为OpeningFcn()
function myGui_OpeningFcn(hObject, eventdata, handles, varargin)
... % anything else you may want to do
% Wait here until user completes gui calculation.
% Without pausing execution here, by default the figure handle
% would be immediately returned to the calling code.
uiwait();
注意:此将阻止您的调用代码中的执行。
打包输出值并在所需的回调中调用uiresume()
。
function btnReturnValue_Callback(hObject, ~, handles)
...
calcValue = doSomeCalculations();
% Set 'output' value which will be returned from this figure.
handles.output = calcValue;
% Update the 'guidata' so the handles.output value just set will be saved.
guidata(hObject, handles);
% Resume execution which was blocked by OpeningFcn().
uiresume();
从其他代码中调用gui并存储结果值。
value = myGui();
返回的值可以是任何matlab对象(用户类,结构,单元格等)。