image thumbnail


version (1.1 KB) by Gerald Dalley
Assert function that expands like the C macro assert


Updated 07 Nov 2006

No License

% Evaluates the test condition in the caller's context. If the result is
% false, an error is thrown indicating that the test failed.
% TESTCONDITION should be a string.
% If TRUTHVALUE is zero, an error is thrown. The text of the error
% contains ERRMSG if supplied. This version of ASSERT was made to
% promote compatibility with Kevin Murphy's Bayes Net Toolbox (i.e. he
% uses this syntax). TRUTHVALUE must be a logical or a number.
% assert('1==2') ==> assertion error generated
% assert(1==2) ==> assertion error generated (BNT syntax)
% assert 1==2; ==> assertion error generated
% x=1; assert('x==1') ==> no error
% x=1; assert x==1; ==> no error
% assert('{a==3') ==> error generated by Matlab (bad assert code)

Cite As

Gerald Dalley (2022). assert.m (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Assertion function

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!