MATLAB: Passing Transforming function to step method of matlab.system.System

MATLABMATLAB Compilermatlab.system.systemobject-orientedoopprogrammingstep method

Goal: Apply the transform object T to the input data x, in a specefic manner as class A states.
Description: I have a class which does a specefic analyis called T, and another class which want to deploy an object from T on the data, x, in a specific order (class A). A is inherited from matlab.system.System because I can develop my code easier using "step Method" and blah blah. Step method just takes variables and fi objects but not function_handle or a external object (btw why? is it possible in general?). So I import the T object to the A.Func property and pass it to step method. In step method I call the A.Func.do to perform my desired T analysis. I couldn't find any other way 🙁 (I'm newbie). But i constantly get a weird error which I don't understand.
Analysis class T:
classdef T < handle
properties
N
end
methods
% CONSTRUCTOR:
function obj = T(n)
if nargin == 1
obj.N = n;
else
obj.N = 16;
end
end
function y = do(x)
y = abs(fft(x,obj.N));
end
end
end
Structering Class A:
classdef A < matlab.system.System
properties
W % numeric properties
Func % function handle or object
end
methods
% constructor
function obj = A(Func,w)
if nargin == 2
obj.W = w;
obj.Func = Func;
else % you can use default assining in the properties instead...
obj.W = 16;
obj.Func = @(x) sin(x);
end
end
end
methods (Access=protected)
function y = stepImpl(obj,x)
y = obj.Func.do(x)*obj.W;
end
function numIn = getNumInputsImpl(~)
numIn = 1;
end
end
end
and the main script is:
clear all
clc
x = linspace(0,10*pi,100);
a = T(100);
b = A(T,3);
step(b,x)
but I get this error:
Error using T/do
Too many input arguments.
Error in A/stepImpl (line 30)
y = obj.Func.do(x)*obj.W;
Error in Main (line 9)
step(b,x)
Class T Code:
Class A Code:

Best Answer

Hi, Marry Christmass,
The problem was solved by a technique called object composition. Just for documenting, in the case of static method "." operator should be used. and with the superclass "@" operator. (and bunch of concepts about superiority/inferiority) ... however using direct call (some sort of overloading) was enough to have a working class:
Class A:
classdef A < matlab.system.System
properties
W % numeric properties
Func % function handle or object
end
methods
function obj = A(Func,w)
if nargin == 2
obj.W = w;
obj.Func = Func;
else
obj.W = 16;
obj.Func = @(x) sin(x);
end
end
end % method

methods (Access=protected)
function y = stepImpl(obj,x)
y = do(obj.Func,x)*obj.W;
end
function numIn = getNumInputsImpl(~)
numIn = 1;
end
end
end
Class T:
classdef T < handle
properties
N
end
methods
function obj = T(n)
if nargin == 0
obj.N = 16;
end
if nargin == 1
obj.N = n;
end
end
function y = do(obj,x)
y = abs(fft(x,obj.N));
end
end
end % method
Main Script:
clear all
clear classes
clc
x = linspace(0,10*pi,100);
a = T(100);
b = A(T,3);
step(b,x)