view assertSize.m @ 1118:07d0caf915e4 feature/poroelastic

Introduce optFlag so that one can choose not to build the optimization-related cell of matrices called B. It is too computationally costly and should probably be done in a different way.
author Martin Almquist <malmquist@stanford.edu>
date Sun, 05 May 2019 19:05:31 -0700
parents dec0447cbf2c
children a72038b1f709
line wrap: on
line source

% 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