overloading subsref() in a Heterogeneous class
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!