function elementWiseOpCheckInputs(A, B, errMsg)
%elementWiseOpCheckInputs helper to check if A and B are compatible for
% element-wise operation taking into account dimension expansion. Throw 
% errMsg if it's not the case.

%   Copyright 2020 The MathWorks, Inc.

    dimsA = size(A);
    dimsB = size(B);
    minSz = min(length(dimsA), length(dimsB));
    szA = dimsA(1:minSz);
    szB = dimsB(1:minSz);
    if ~all(szA == szB | szA == 1 | szB == 1)
        error(errMsg);
    end
end
