0

当我按下按钮到我的主 m 文件时,我试图从两个编辑文本中传递值。我从 GUI 获取数据,但我不能调用 main 并在那里传递值。这就是我到目前为止所做的。GUI(GUIDE)代码

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 中使用函数吗?提前致谢

4

1 回答 1

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将是一个空单元格

可以有任意数量的输入。

于 2013-06-28T02:18:43.747 回答