| MATLAB Function Reference | ![]() |
assert(expression)
assert(expression, 'errmsg')
assert(expression, 'errmsg',
value1, value2, ...)
assert(expression, 'msg_id', 'errmsg',
value1, value2, ...)
assert(expression) evaluates expression and, if it is false, displays the error message: Assertion Failed.
assert(expression, 'errmsg') evaluates expression and, if it is false, displays the string contained in errmsg. This string must be enclosed in single quotation marks. When errmsg is the last input to assert, the MATLAB® software displays it literally, without performing any substitutions on the characters in errmsg.
assert(expression, 'errmsg', value1, value2, ...) evaluates expression and, if it is false, displays the formatted string contained in errmsg. The errmsg string can include escape sequences such as \t or \n, as well as any of the C language conversion operators supported by the sprintf function (e.g., %s or %d). Additional arguments value1, value2, etc. provide values that correspond to and replace the conversion operators.
See Formatting Strings in the MATLAB Programming Fundamentals documentation for more detailed information on using string formatting commands.
MATLAB makes substitutions for escape sequences and conversion operators in errmsg in the same way that it does for the sprintf function.
assert(expression, 'msg_id', 'errmsg', value1, value2, ...) evaluates expression and, if it is false, displays the formatted string errmsg, also tagging the error with the message identifier msg_id. See Message Identifiers in the MATLAB Programming Fundamentals documentation for information.
This function tests input arguments using assert:
function write2file(varargin)
min_inputs = 3;
assert(nargin >= min_inputs, ...
'You must call function %s with at least %d inputs', ...
mfilename, min_inputs)
infile = varargin{1};
assert(ischar(infile), ...
'First argument must be a filename.')
assert(exist(infile)~=0, 'File %s not found.', infile)
fid = fopen(infile, 'w');
assert(fid > 0, 'Cannot open file %s for writing', infile)
fwrite(fid, varargin{2}, varargin{3});![]() | asinh | assignin | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |