-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds optional validation for whole numbers to validateNumber (#260)
* Adds optional validation for whole numbers to validateNumber * Addresses review comment
- Loading branch information
1 parent
d626445
commit 6c6c1c5
Showing
4 changed files
with
33 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
function input = validateNumber(input, message) | ||
function input = validateNumber(input, message, validateInt) | ||
% Checks input is a number and throws an exception with given message. | ||
% | ||
% If validateInt is true, also check that input is a whole number. | ||
% | ||
% validateNumber(2, 'This is not a number'); | ||
% validateNumber(2.5, 'This is not a whole number', true); | ||
arguments | ||
input | ||
message {mustBeTextScalar} = 'The input is not a number' | ||
validateInt {mustBeA(validateInt,'logical')} = false | ||
end | ||
|
||
if ~isnumeric(input) | ||
throw(exceptions.invalidType(message)); | ||
elseif validateInt && mod(input, 1) ~= 0 | ||
throw(exceptions.invalidValue(message)); | ||
end | ||
end |