MATLAB: How to parse two input arguments for matching dimensions with Matlab Input Parser

inputMATLABparser

I use the Matlab Inputparser Class to validate function input, this is a minimal example:
function C = multiplyMatrix(A, B)
p = inputParser;
addRequired(p, 'A', @isnumeric); % Line A
addRequired(p, 'B', @isnumeric);
parse(p, A, B);
if size(A, 2) ~= size(B, 1) % Line B
error('Size mismatch.');
end
C = A*B;
end
How do I integrate tests spanning more than one variable (i.e. the if-statement in Line B) in the concept of the Matlab Inputparser Class? I only found out how to create tests regarding one variable (see Line A).
I am also happy about comments about the usage of this Parser in total.
(I had asked this question on stackoverflow.com before, but I feel like this is the better place to ask.)

Best Answer

Unfortunately, you cannot do that inside inputParser. For each parameter you can only supply a function that validates just that parameter. Any tests involving more than one parameter have to be done separately, after you call parse().