overloading subsref() in a Heterogeneous class

1 view (last 30 days)
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

Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!