Calling Sequence GenerateSBlock(system, sourcename, blockname, opts)

Parameters

 system - System; object to be exported sourcename - string; main S-Function block file name blockname - string; Simulink® block diagram file name opts - (optional) equation(s) of the form option = value; specify options for GenerateSBlock

Description

 • The GenerateSBlock command generates a sequence of MATLAB® commands (referred to as m-script commands) that compile the code generated by MapleSimConnector[SBlock] for the system object and create a Simulink® diagram (with the name specified by blockname that calls the compiled code (whose source file is specified by sourcename).
 • The m-script commands are generated as a single string (with each line of code separated by the new line character "\n"). The generated m-script code string can be saved to a file (using MapleSimConnector[SaveCode]).
 • If the target option is C, the generated script first creates a call to the mex MATLAB® command to compile the C file. This requires the mex command to be set up in MATLAB® before executing the generated code. Refer to MapleSimConnector[setup] for instructions on how to set up the mex command.
 • The generated m-script commands, upon execution in MATLAB®, call Simulink® to create either a Model or Library diagram. The type of diagram to be created is specified by the model option (see the Options section). Simulink® must be installed and configured before you can execute the generated code.
 • The resulting Simulink® block consists of a single Subsystem block, whose name is specified by blockname. This blockname subsystem has the same number of input and output ports as in the given system. Within the blockname subsystem, it contains five main elements: input ports; a MUX block; a S-Function block; a DEMUX block; and output ports.
 – The name of the Input Ports (inports) are extracted from the given system object.
 – The MUX block combines the inputs into a single signal vector to be connected to the S-Function block. The MUX block is given the name Inputs.
 – The S-Function block has only a single input vector and a single output vector. The name of the S-Function block is given by blockname.
 – The DEMUX block separates multiple output signals from the S-Function block. The DEMUX block is given the name Outputs.
 – The name of the Output Ports (outports) is also extracted from the given system object.
 – A mask is created for the Subsystem block if the parameters option is specified. The parameters must be of the type symbol. The parameter variables are available in the mask for user modification during execution time within MATLAB®. The prompt label for each parameter listed in the mask is generated from the strings specified by the labels option. If the labels option is not specified, the left-hand side of the equations defined in the parameters option is used to generate the prompt label for the mask.

Examples

 > $\mathrm{with}\left(\mathrm{MapleSimConnector}\right):$

Parameter values

 > $\mathrm{par}:=\left[m=5,b=2,k=3\right]$
 ${\mathrm{par}}{:=}\left[{m}{=}{5}{,}{b}{=}{2}{,}{k}{=}{3}\right]$ (1)

Differential equation.

 > $\mathrm{de}:=m\left(\frac{{ⅆ}^{2}}{ⅆ{t}^{2}}y\left(t\right)\right)+b\left(\frac{ⅆ}{ⅆt}y\left(t\right)\right)+ky\left(t\right)=u\left(t\right)$
 ${\mathrm{de}}{:=}{m}{}\left(\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{t}}^{{2}}}{}{y}{}\left({t}\right)\right){+}{b}{}\left(\frac{{ⅆ}}{{ⅆ}{t}}{}{y}{}\left({t}\right)\right){+}{k}{}{y}{}\left({t}\right){=}{u}{}\left({t}\right)$ (2)
 > $\mathrm{sys1}:=\mathrm{DynamicSystems}:-\mathrm{DiffEquation}\left(\mathrm{de},\mathrm{inputvariable}=\left[u\left(t\right)\right],\mathrm{outputvariable}=\left[y\left(t\right)\right]\right)$
 ${\mathrm{sys1}}{:=}\left[\begin{array}{c}{\mathbf{Diff. Equation}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{u}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{y}{}\left({t}\right)\right]\end{array}\right$ (3)
 > $\mathrm{script}:=\mathrm{SBlock}:-\mathrm{GenerateSBlock}\left(\mathrm{sys1},"SpringMassDamper_C1","Block",\mathrm{parameters}=\mathrm{par}\right):$