User`s guide
4 Guidelines for Writing C MEX S-Functions
4-38
matlabroot/toolbox/simulink/blocks/sfun_directlook.tlc
%% File : sfun_directlook.tlc
%% Abstract:
%% Level-2 S-function sfun_directlook block target file.
%% It is using direct lookup algorithm without interpolation.
%%
%% Copyright (c) 1994-1998 by The MathWorks, Inc. All Rights Reserved.
%% $Revision: 1.3 $
%implements “sfun_directlook” “C”
%% Function: BlockTypeSetup ====================================================
%% Abstract:
%% Place include and function prototype in the model’s header file.
%%
%function BlockTypeSetup(block, system) void
%% Add this external function’s prototype in the header of the generated
%% file.
%%
%openfile buffer
extern int_T GetDirectLookupIndex(const real_T *x, int_T xlen, real_T u);
%closefile buffer
%<LibCacheFunctionPrototype(buffer)>
%endfunction
%% Function: mdlOutputs ========================================================
%% Abstract:
%% Direct 1-D lookup table S-function example.
%% Here we are trying to compute an approximate solution, p(x) to an
%% unknown function f(x) at x=x0, given data point pairs (x,y) in the
%% form of a x data vector and a y data vector. For a given data pair
%% (say the i’th pair), we have y_i = f(x_i). It is assumed that the x
%% data values are monotonically increasing. If the first or last x is
%% outside of the range of the x data vector, then the first or last
%% point will be returned.
%%
%% This function returns the “nearest” y0 point for a given x0.
%% No interpolation is performed.
%%
%% The S-function parameters are:
%% XData
%% YData
%% XEvenlySpaced: 0 or 1
%% The third parameter cannot be changed during execution and is
%% written to the model.rtw file in XSpacing filed of the SFcnParamSettings
%% record as “EvenlySpaced” or “UnEvenlySpaced”. The first two parameters
%% can change during execution and show up in the parameter vector.
%%