title: Does cross-argument function argument validation not work with (Repeating) arguments?
body: <h3>Summary</h3>
  <p>When using <a href="https://www.mathworks.com/help/matlab/matlab_prog/function-argument-validation-1.html" rel="nofollow noreferrer">function argument validation</a> that depends on multiple
  arguments in a <code>(Repeating)</code> arguments block, the current argument is passed
  to the validation function normally while other arguments are passed as
  partially-populated
  cell arrays. This contasts with how things work in non-<code>(Repeating)</code> arguments blocks. Is this the expected behavior or a bug?</p>
  <h3>Scenario</h3>
  <p>Consider the function <code>dummy1</code> below, which uses the custom <a href="https://www.mathworks.com/help/matlab/matlab_prog/function-argument-validation-1.html#mw_d3c46813-2f36-4bfe-8cfa-ba9157619c06" rel="nofollow noreferrer">argument validation
  function</a>
  <code>mustBeEqualSize</code> to ensure that the arguments <code>x</code> and <code>y</code> have the same size.
  Since the validation of <code>y</code> depends on the value of <code>x</code>, I'm calling this
  &quot;cross-argument&quot; validation<sup>*</sup>.</p>
  <p><sup>*If there's a better term for this,
  please comment or edit.</sup></p>
  <pre><code>function dummy1(x, y)
      arguments
         x (1,:) 
         y (1,:) {mustBeEqualSize(x,y)}
      end
      % Do something with x and y.
  end
  
  function mustBeEqualSize(a, b)
      % Validates that function arguments have the same size.
      if ~isequal(size(a), size(b))
          eid = 'Size:notEqual';
          msg = &quot;Arguments must have the same size.&quot;;
          throwAsCaller(MException(eid, msg))
      end
  end
  </code></pre>
  <p>As written, this form of argument validation works as expected:</p>
  <pre><code>dummy1(1:3, 4:6)  % arguments have same size; validation passes (okay)
  dummy1(1:3, 4:7)  % arguments have different size; validation fails (okay)
  </code></pre>
  <p>In both cases, when <code>mustBeEqualSize</code> is called during argument
  validation for <code>y</code>, both <code>a</code> and <code>b</code> are received as 1xN double arrays,
  which matches my expectations:</p>
  <pre><code>% Inside call to mustBeEqualSize(x,y), when x=1:3, y=4:6 in dummy1
  a =
       1     2     3
  b =
       4     5     6
  </code></pre>
  <p>The problem arises when <code>dummy1</code> is modified to accept repeating
  arguments by adding <code>(Repeating)</code> to the arguments block:</p>
  <pre><code>function dummy2(x, y)
      arguments (Repeating)
         x (1,:) 
         y (1,:) {mustBeEqualSize(x,y)}
      end
      % Do something with each pair of x-y arguments.
      % In this body, both x and y will be 1xN cell arrays, where N is the
      % number of argument groups passed.
  end
  </code></pre>
  <p>Now when we call <code>dummy2(1:3, 4:6)</code>, argument validation fails. Using the
  debugger, I found that when <code>mustBeEqualSize</code> is called during the
  validation of <code>y</code>, <code>a</code> is received as a 1x1 cell array while <code>b</code> remains a 1x3 double array:</p>
  <pre><code>% Inside call to mustBeEqualSize(x,y), when x=1:3, y=4:6 in dummy2
  a =
    1×1 cell array
      {[1 2 3]} 
  b =
       4     5     6
  </code></pre>
  <p>The issue is even more obvious when more repeating argument are used:</p>
  <pre><code>dummy2(1:3, 4:6, 1:3, 4:6, 1:3, 4:6)  % 3 argument groups
  </code></pre>
  <p>results in</p>
  <pre><code>a =
    1×3 cell array
      {[1 2 3]}    {0×0 double}    {0×0 double}
  b =
       4     5     6
  </code></pre>
  <p>It seems that during the validation of <code>y</code> in <code>dummy2</code>, <code>y</code> takes on the value of the
  current argument being validated while <code>x</code> is a (parially populated)
  cell array buffer that MATLAB allocated to hold all of the <code>x</code>-arguments
  that were passed.</p>
  <p>This of course breaks the cross-argument validation, since only the
  argument currently being validated actually presents itself as a single
  argument, while other arguments present themsevles as cell array
  buffers.</p>
  <h3>Question</h3>
  <p>Is the mismatch between how cross-argument validation works for <code>(Repeating)</code> versus non-<code>(Repeating)</code> arguments a bug, or is cross-argument validation with <code>(Repeating)</code> arguments not supported in MATLAB? If this difference in behavior is expected, is there any way to make cross-argument validation work with <code>(Repeating)</code> arguments?</p>
  <p>The MATLAB docs say the following about argument validation with
  Repeating arguments</p>
  <blockquote>
  <p>In the function, each repeating argument becomes a cell array with the
  number of elements equal to the number of repeats passed in the function
  call. The validation is applied to each element of the cell array.</p>
  </blockquote>
  <p>which doesn't seem to shed any light on how <em>cross-argument</em> validation
  should work with repeating arguments.</p>
  <p>Tested using MATLAB R2021a (9.10.0.1602886).</p>