[S(:).b] = deal(0)
is equivalent to [S(1:end).b] = deal(0)
, which expands to [S(1:numel(S)).b] = deal(0)
, or, in your particular case [S(1:0).b] = deal(0)
. Thus, you deal to none of the elements of the structure, which I'd expect to work, though I still find it somewhat surprising that this will add a field b
. Maybe it is this particular weirdness, which you can only access through explicitly specifying the list of fields, that is caught by the error.
Note that if you want to create an empty structure with field b
, you can alternatively write
S(1:0) = struct('b',pi) %# pie or no pie won't change anything
though this gives a 0x0 structure.