如何在matlab中关闭输入对话框?

时间:2012-12-29 03:10:39

标签: matlab

如何在不输入任何值的情况下直接关闭输入对话框?对于'menu'函数,我们可以使用while选项== 0表示未选择的选项,但输入对话框怎么样?

prompt = {'输入收益:','输入范围:'};

dlg_title ='输入值';

num_lines = 1;

def = {'20','256'}; %默认

answer = inputdlg(prompt,dlg_title,num_lines,def);

%%%获取两个输入值%%%%

%A = getfield(回答,{1}); %第一个输入字段

A = str2double(回答{1});

%B = getfield(回答,{2}); %second输入字段

B = str2double(回答{2});

假设我有一个如图所示的输入对话框,我可以用完整的方式对循环进行建模

1 个答案:

答案 0 :(得分:1)

您无法阻止它被关闭,但您可以使用while循环重新打开它,直到用户输入有用的值。

done = false;
while ~done
    a=inputdlg('enter a number')
    num = str2double(a{1}); %# will turn empty and strings into NaN
    if isnumeric(num)
       done = true;
    else
       %# keep running while loop
       %# you can pop up an errordlg box here to tell the user what was wrong.
       %# It would be nice if you were to set the inputs that passed the test
       %# as defaults for the next call of inputdlg. Nothing sucks as much 
       %# as having to completely re-fill a form because of a small typo
    end
end