"Why is that?"
The answer is surprisingly simple: the explicit syntax
is considered as three separate evaluations, much as if you had written them on three different lines:
This is explained in the documentation for the comma, and also in the documentation for entering statements, which states "You also can enter more than one statement on the same line by separating statements. To distinguish between commands, end each one with a comma or semicolon. Commands that end with a comma display their results, while commands that end with a semicolon do not." This means you will get exactly the same error, even if you just try to allocate one array on the RHS to multiple arrays/locations on the LHS:
Of course we cannot allocate one array to three arrays! But we can make it work (and also demonstrate exactly what is happening) by simply replacing the first argument with a function that returns sufficient outputs:
>> A = struct('number', cell(1,3));
1x3 struct array with fields:
Note that the 2 and 3 are parsed, displayed, and discarded! The function I used is given here:
In contrast, the comma-separated lists that are generated from either a cell array or a structure are all forms of indexing, which means that ultimately they call subsref, which apparently can return multiple outputs (as in general MATLAB functions can). As subsref is builtin we cannot easily add breakpoints :(
My guess is that this is limited to RHS explicitly-written comma-separated lists only, but this is just a guess.
- explicitly-written comma-separated lists on the RHS request all of the outputs from the first list argument.
- generated comma-separated lists (attempt to) return as many outputs from subsref as the LHS requests.