S function with function handle as class member of block.
Show older comments
Problem statement: I want to preload my function handel form mat file in level-2 s-function. After that, I want to call each iteration.
Code sample:
function msfcn_times_two(block)
% Level-2 MATLAB file S-Function for times two demo.
% Copyright 1990-2009 The MathWorks, Inc.
setup(block);
%endfunction
function setup(block)
%% Register number of input and output ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
%% Setup functional port properties to dynamically
%% inherited.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).DirectFeedthrough = true;
%% Set block sample time to inherited
block.SampleTimes = [-1 0];
%% Set the block simStateCompliance to default (i.e., same as a built-in block)
block.SimStateCompliance = 'DefaultSimState';
%% Run accelerator on TLC
block.SetAccelRunOnTLC(true);
%% Register methods
block.RegBlockMethod('Outputs', @Output);
%% import function
block.lam=load("lmbd.mat")
%endfunction
function Output(block)
M = block.lam.Mfunc(0,0,0,0,0,0,0,0,0,0,0,0);
block.OutputPort(1).Data = 2*block.InputPort(1).Data;
%endfunction
How to load function handle as class member?
Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Create MATLAB S-Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!