MATLAB: Overloading Equality Operator for Arrays

equalityMATLABobject arrayoverload operator

I have a class with the eq() operator overloaded, but I'm not sure the best way to make it work with object arrays, in a similar way to the way standard arrays work for equality. Here's the code that I have right now. For reference, the class is designed to work with spheres in 3D space, with a center [x, y, z] and a radius.
function test=eq(a,b)
if all(size(a.xyz)==size(b.xyz))
if (a.radius==b.radius)
test=all(a.xyz==b.xyz);
else
test=false;
end
else
test=false;
end
end

Best Answer

Perhaps as follows
function test=eq(a,b)
test = all([a.xyz]==[b.xyz]) & all([a.radius]==[b.radius]);
end