overloading subsref() in a Heterogeneous class
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to overload subsref() in my class, however I noticed that whenever I use Heterogeneous arrays in my class definition, MATLAB does not allow me to overwrite subsref() :
classdef testsubsref < matlab.mixin.Heterogeneous & handle % produces an error for subsref()
% classdef testsubsref < handle % does not prodcue an error for subsref()
properties
x=0;
end
methods
function obj = testsubsref(val)
if nargin>0
obj.x=val;
end
end
function y = f(obj)
y=2*obj.x;
end
function sref = subsref(obj,S)
fprintf('in subsref \n');
sref = builtin('subsref',obj,S);
end
end
end
For example,
c=testsubsref(1)
Error using testsubsref
Class 'testsubsref' is not allowed to define a 'subsref' method.
When matlab.mixin.Heterogeneous is removed from the class definition the subsref() works as expected.
My guess is that matlab.mixin.Heterogeneous uses subsref() for its imeplementation, and makes it Sealed (?)
Any suggestion how to make a subsref() for a class with heterogeneous arrays?
Thanks Arnon
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Numeric Types dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!