将值从GUI传递到m文件MATLAB

时间:2013-06-27 23:03:41

标签: user-interface matlab

当我按下按钮到我的主m文件时,我试图从两个edittexts传递值。我从GUI获取数据,但我无法调用main并将值传递给那里。这就是我到目前为止所做的。 GUI(指南)代码

function resultbutton_Callback(hObject, eventdata, handles)
% hObject    handle to resultbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
N=str2num(get(handles.edituser,'String'));
f=str2num(get(handles.editfrequency,'String'));

我还应该在这里和主程序中写些什么。我应该在main使用功能吗? 提前致谢

1 个答案:

答案 0 :(得分:1)

使用inputdlg可能是让您完成工作的最简单方法。

... % Initialization

% Open a dialog box and wait for user to input two numbers.
dlg_title = 'Input';
num_lines = 1;
prompt = {'Input 1:','Input 2:'}; % label for each input
def = {'10','20'}; % default values of each input
answer = inputdlg(prompt, dlg_title, num_lines, def); % open dialog box

if ~isempty(answer) % only if OK button was clicked
    N = str2double(answer{1});
    f = str2double(answer{2});
end
... % Continue calculations

请注意,如果用户关闭了窗口,answer将是空单元格

可能有任意数量的输入。