User interface matlab图形用户界面中的用户输入
大家好, 我正在构建一个gui,其中有一个编辑框,等待用户编写名称 目前,我强制用户使用以下代码提供合法名称:User interface matlab图形用户界面中的用户输入,user-interface,matlab,user-input,edit,User Interface,Matlab,User Input,Edit,大家好, 我正在构建一个gui,其中有一个编辑框,等待用户编写名称 目前,我强制用户使用以下代码提供合法名称: NewPNUName = get(handles.nameOfNewPNU, 'String'); if ( isempty(NewPNUName) ||... strcmp(NewPNUName,'Enter the name for the new PNU') ) errordlg('Please enter a name for the new PNU.'
NewPNUName = get(handles.nameOfNewPNU, 'String');
if ( isempty(NewPNUName) ||...
strcmp(NewPNUName,'Enter the name for the new PNU') )
errordlg('Please enter a name for the new PNU.');
elseif (~ischar(NewPNUName(1)))
errordlg('The PNU name should start with a letter.');
else
handles.NewPNUName = NewPNUName;
end
if (~isempty(handles.NewPNUName))
% Do all the things needed if there is a legit name
end
如果用户没有写一个合法的名字,它什么也做不了。
我想让它做的是用一个编辑框弹出一个窗口,要求用户再次输入想要的名字,直到它成为一个合法的名字
谢谢你的帮助
编辑:
按照@woodchips的建议,我将代码更正为以下内容:
NewPNUName = get(handles.nameOfNewPNU, 'String');
ValidName = ~isempty(NewPNUName) && isletter(NewPNUName(1)) &&...
~strcmp(NewPNUName,'Enter the name for the new PNU');
while (~ValidName)
if ( isempty(NewPNUName) ||...
strcmp(NewPNUName,'Enter the name for the new PNU') )
NewPNUName = char(inputdlg('Please enter a name for the new PNU.','No name entered'));
elseif (~isletter(NewPNUName(1)))
NewPNUName = char(inputdlg('The name of the new PNU should start with a letter. Please enter a new name',...
'Invalid name entered'));
else
allConds = 'are met'
end
ValidName = ~isempty(NewPNUName) && isletter(NewPNUName(1)) &&...
~strcmp(NewPNUName,'Enter the name for the new PNU');
end
因此,在代码块周围放置一个while循环,该循环生成一个inputdlg框。将while循环的条件设置为结果有效。因此,在生成inputdlg框的代码块周围放置一个while循环。将while循环的条件设置为结果有效