I'm having trouble understanding the following code snippet. The simple call looks like this, without any assignment or else:
expression1@expression2;
expression2
is referring to a self defined handle class.
I've looked into handles but couldn't figure out what the given calling structure does, from the normal examples @(x) x^2;
or f = @sin;
and couldn't find similar examples online.
Any help on what the notation might do is appreciated.
Without context it's hard to say for sure, but this looks like a subclass calling the superclass method (usually before additional functionality in the subclass implementation)...
See the docs here.
Example from the linked docs:
classdef Sub < Super
methods
function foo(obj)
% preprocessing steps
...
foo@Super(obj);
% postprocessing steps
...
end
end
end
In this case, the foo
function is defined in the Super
class, implemented in the subclass Sub
, and extended (with preprocessing and postprocessing). The foo@Super(obj)
notation calls the superclass method from the subclass.
Note that this is analogous to SuperObj.foo(obj)
, except you don't have an instantiated object (SuperObj
) of class Super
to make this call. And since you're extending / overriding the superclass version of the function, you can't just call obj.foo()
as you would if the subclass implementation was identical - that's the function you're already in! Hence the need for this different notation.