Mercurial > repos > public > sbplib
diff assertSize.m @ 797:5cf9fdf4c98f feature/poroelastic
Merge with feature/grids and bugfix bcSetup
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Thu, 26 Jul 2018 10:53:05 -0700 |
parents | dec0447cbf2c |
children | a72038b1f709 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/assertSize.m Thu Jul 26 10:53:05 2018 -0700 @@ -0,0 +1,16 @@ +% Assert that array A has the size s. +function assertSize(A,varargin) + if length(varargin) == 1 + s = varargin{1}; + errmsg = sprintf('Expected %s to have size %s, got: %s',inputname(1), toString(s), toString(size(A))); + assert(all(size(A) == s), errmsg); + elseif length(varargin) == 2 + dim = varargin{1}; + s = varargin{2}; + + errmsg = sprintf('Expected %s to have size %d along dimension %d, got: %d',inputname(1), s, dim, size(A,dim)); + assert(size(A,dim) == s, errmsg); + else + error('Expected 2 or 3 arguments to assertSize()'); + end +end