【问题标题】:how to prevent input dialog box be closed in matlab?如何防止在matlab中关闭输入对话框?
【发布时间】:2016-12-19 03:12:45
【问题描述】:

如何避免用户直接关闭输入对话框而不输入任何值?对于 'menu' 功能,我们可以使用 while options==0 来形成循环以用于未选择的选项,但是输入对话框呢?

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

dlg_title = '输入值';

num_lines=1;

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

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

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

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

A = str2double(answer{1});

%B = getfield(answer,{2}); %第二个输入字段

B = str2double(answer{2});

假设我有一个如图所示的输入对话框,我如何使用循环完整地对其进行建模

【问题讨论】:

    标签: matlab


    【解决方案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
    

    【讨论】:

    • 我仍然不太清楚如何创建循环。我已经编辑了我的问题,你能帮我一把吗..非常感谢........@Jonas
    • 如何在对话框中提示不满足特定条件的输入的错误消息并阻止整个对话框执行,直到所有输入都满足特定条件@Jonas
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 2022-01-06
    相关资源
    最近更新 更多