This behavior seems rather inconsistent, especially since by my understanding of short-circuit logic the A.(x) bit should not be evaluated if isfield(A,x) is false. Can someone help me understand this behavior? Thank you!
>> A = struct('apple',1, 'orange',1);>> x = 'apple';>> isfield(A,x) && A.(x)ans = 1>> x = 'banana';>> isfield(A,x) && A.(x)ans = 0>> isfield(A,x) & A.(x)Reference to non-existent field 'banana'.>> for x = {'apple','banana'}.. isfield(A,x) && A.(x).. endArgument to dynamic structure reference must evaluate to a valid field name.
Best Answer