-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckInput.m
More file actions
29 lines (28 loc) · 1.03 KB
/
Copy pathCheckInput.m
File metadata and controls
29 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [ output ] = CheckInput( hObject, tipObject, max, min, wrong_color, right_color, string)
%UNTITLED 此处显示有关此函数的摘要
% 此处显示详细说明
% 用于检查文本正确性,保证为数字而且在合理范围内
text = get(hObject, 'string');
text = str2double(text);
% 如果文本输入错误
if isnan(text)
set(hObject, 'backgroundcolor', wrong_color);
message = sprintf('输入%s不符合规范,请重新输入!', string);
set(tipObject, 'string', message);
output = false;
% 如果数值大小超过可行范围
elseif text > max
set(hObject, 'backgroundcolor', wrong_color);
message = sprintf('输入%s过大,请重新输入!合适的范围为%0.5f至%0.5f之间', string, min, max);
set(tipObject, 'string', message);
output = false;
elseif text < min
set(hObject, 'backgroundcolor', wrong_color);
message = sprintf('输入%s过小,请重新输入!合适的范围为%0.5f至%0.5f之间', string, min, max);
set(tipObject, 'string', message);
output = false;
else
set(hObject, 'backgroundcolor', right_color)
set(tipObject, 'string', '')
output = true;
end