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 allclcx = linspace(0,10*pi,100);a = T(100);b = A(T,3);step(b,x)
but I get this error:
Error using T/doToo 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