MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
property. Because there is a loop in stepImpl, assign the pMethodHandle property to a
local method handle, myFun, and then use myFun inside the loop.

classdef MyClass < matlab.System
function setupImpl(obj)
if strcmp(obj.Method, 'Method1')
obj.pMethodHandle = @myMethod1;
else
obj.pMethodHandle = @myMethod2;
end
end
function y = stepImpl(obj,x)
myFun = obj.pMethodHandle;
for p=1:1000
y = myFun(obj,x)
end
end
end
function y = myMethod1(x)
y = x+1;
end
function y = myMethod2(x)
y = x-1;
end
end

Simulink


For System objects being included in Simulink, add the StrictDefaults attribute. This
attribute sets all the MutableImpl methods to return false by default.

Code Generation


For information about System objects and code generation, see “System Objects in
MATLAB Code Generation” (MATLAB Coder).

34 System object Usage and Authoring

Free download pdf