use*_*886 1 matlab operator-overloading operator-keyword
我希望能够在MATLAB中重载索引操作符 ()
和{}
我的类.特别是,我希望能够定义类方法,如...
% ...
classdef MyClass < handle
% ... other class definition stuff...
function returnVal = operator{}(indexRange)
%....implementation here....
end
function returnVal = operator()(indexRange)
%....implementation here....
end
end
Run Code Online (Sandbox Code Playgroud)
这样我就可以创建对象并做...
x = MyClass();
returnedVals = x(:);
returnedCells = [x{:}];
% etc.
Run Code Online (Sandbox Code Playgroud)
这在MATLAB中是否可行?我知道这在C++和python中很容易(分别通过重载operator []
和__get__
运算符).Mathworks网站本身并不太清楚如何做到这一点.