what @ does in MATLAB?
40 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Md Jonayet
el 19 de Abr. de 2023
Editada: per isakson
el 20 de Abr. de 2023
I have a class name VI_Lecroy.
function obj = VI_SDA6000(varargin)
obj = obj@VI_LeCroy(varargin{:});
end
What this @ does?
2 comentarios
Walter Roberson
el 19 de Abr. de 2023
@ in other contexts is used for function handles, but in the context of being in the middle of a pair of words, is a superclass reference.
Respuesta aceptada
chicken vector
el 19 de Abr. de 2023
Editada: chicken vector
el 19 de Abr. de 2023
In this case @ is used to call a superclass method from a subclass.
Consider the classes Food and Donut, such that Donut is a subclass of Food.
If Food has a method eat, you can call this method from the subclass Donut using the operator @:
%% Food class:
classdef Food
methods
% Constructor
function obj = Food(varargin)
...
end
function eatenFood = eat(varargin)
...
end
end
end
%% Donut class:
classdef Donut < Food
methods
% Constructor
function obj = Donut(varargin)
...
end
function eatenDonut = eat(varargin)
eatenDonut = eat@Food(varargin)
end
end
end
In particular, obj@Food calls the constructor method that is used to define class instances.
This is the method that has the same name of the class itself.
It follows that:
function obj = VI_SDA6000(varargin)
obj = obj@VI_LeCroy(varargin{:});
end
implies that the instances of the class VI_SDA6000 are constructed in the same way as done in VI_LeCroy.
1 comentario
Adam Danz
el 19 de Abr. de 2023
Más respuestas (0)
Ver también
Categorías
Más información sobre Food Sciences en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!