MapleSimConnector[SBlock]
GenerateSBlock
generate code to create a Simulink® diagram
Calling Sequence
Parameters
Options
Description
Examples
GenerateSBlock(system, sourcename, blockname, opts)
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
The opts arguments are optional arguments of the form option = value, where option is one of the names listed below. These arguments correspond to keyword parameters; the left side of an equation is the keyword, the right side is the value. Each keyword parameter has a default value that is assigned if the parameter is not passed.
The following paragraphs describe each of the keyword parameters. The first line of each paragraph specifies the format of the argument: the left side is the keyword and the right side specifies the type of the value. If the type is truefalse, then passing just the keyword is equivalent to passing keyword = true.
labels = list(string)
List of prompt labels for the generated mask of the Simulink® block. The labels list must have the same number of elements as the parameters list. The default is the names of the variables (left-hand side of the equations) of the parameters option.
model = truefalse
Specifies the type of the generated Simulink® diagram. There are two types of Simulink® diagram files: Model or Library. If model is set to true, a Model type Simulink® diagram is generated; otherwise, a Library type Simulink® diagram is created. The default is false.
parameters = list
List of parameter equations for the system. If the parameters list is specified, then a mask is created for the main subblock such that the individual parameter variables are listed and made available for editing in the mask dialog box of the generated Simulink® diagram. If parameters is omitted the settings from SystemOptions(parameters) are used. The parameters option is required when the given system contains symbolic parameters; otherwise, an error is raised when the generated code is executed within MATLAB®. The default is an empty list.
target = C or Matlab
Specifies the type of the main subblock. C indicates the main subblock is generated for a Level-2 C S-Function block. Matlab indicates the main subblock is generated for a Level-1 M-file S-Function block. The default is C.
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.
with⁡MapleSimConnector:
Parameter values
par≔m=5,b=2,k=3
Differential equation.
de≔m⁢diff⁡y⁡t,t,t+b⁢diff⁡y⁡t,t+k⁢y⁡t=u⁡t
de≔m⁢ⅆ2ⅆt2y⁡t+b⁢ⅆⅆty⁡t+k⁢y⁡t=u⁡t
sys1≔DynamicSystems:-DiffEquation⁡de,inputvariable=u⁡t,outputvariable=y⁡t
sys1≔Diff. Equationcontinuous1 output(s); 1 input(s)inputvariable=u⁡toutputvariable=y⁡t
script≔SBlock:-GenerateSBlock⁡sys1,SpringMassDamper_C1,Block,parameters=par:
See Also
MapleSimConnector
MapleSimConnector[SaveCode]
MapleSimConnector[setup]
Matlab
Matlab[evalM]
Matlab[setup]
Download Help Document