Difference between empty Matlab struct S and all elements S(:) -
my question is: difference between s , s(:) if s empty struct.
i believe there difference because of question: adding field empty struct
minimal illustrative example:
s = struct(); %create struct s(1) = []; %make empty [s(:).a] = deal(0); %works [s.b] = deal(0); %gives error the error given:
a dot name structure assignment illegal when structure empty. use subscript on structure.
[s(:).b] = deal(0) equivalent [s(1:end).b] = deal(0), expands [s(1:numel(s)).b] = deal(0), or, in particular case [s(1:0).b] = deal(0). thus, deal none of elements of structure, i'd expect work, though still find surprising add field b. maybe particular weirdness, can access through explicitly specifying list of fields, caught error.
note if want create empty structure field b, can alternatively write
s(1:0) = struct('b',pi) %# pie or no pie won't change though gives 0x0 structure.
Comments
Post a Comment