coder.mapping.utils.create - Create code mappings object for configuring data and function interface for C
and C++ code generation - MATLAB ([original](https://www.mathworks.com/help/rtw/ref/coder.mapping.utils.create.html)) ([raw](?raw))
Main Content
Create code mappings object for configuring data and function interface for C and C++ code generation
Since R2020b
Syntax
Description
[coderMapObj](#mw%5Fd2dc34f6-8970-4efd-a163-3385baeae1fc) = coder.mapping.utils.create([simulinkModel](#mw%5F02d38a5e-734a-47fc-99cf-fb8656f38c28))
creates a code mappings environment for the specified model, if one does not exist, and returns it as the object coderMapObj
. Code mappings associate model data elements and functions with configurations for C or C++ code generation. If code mappings exist for the specified model, the function returns those code mappings as the objectcoderMapObj
.
Examples
Use the programmatic interface to create and use code mappings objects of Simulink models.
Load the model NoCoderMapping
.
simulinkModel = "NoCoderMapping"; load_system(simulinkModel);
Use a try-catch
block to determine whether a code mappings object exists for the model. Inside the try
block, attempt to retrieve the existing object by using function coder.mapping.api.get
. Inside the catch
block, create a new code mappings object by using the function coder.mapping.utils.create
. Store the code mappings object in the variable codeMapObj.
Add print messages to show whether the model had an existing code mappings object or not.
try codeMapObj = coder.mapping.api.get(simulinkModel); fprintf("" + ... " ========================================================\n" + ... " The model already had code mappings.\n" + ... " ========================================================\n"); catch fprintf("" + ... " ==========================================\n" + ... " The model does not have code mappings.\n" + ... " Creating new code mappings for the model.\n" + ... " ==========================================\n"); codeMapObj = coder.mapping.utils.create(simulinkModel); end
========================================== The model does not have code mappings. Creating new code mappings for the model.
Retrieve the storage class of input port inport_1
of the model.
getInport(codeMapObj,"inport_1","StorageClass")
Set the storage class of input port inport_1
to ExportedGlobal
.
setInport(codeMapObj,"inport_1",StorageClass="ExportedGlobal")
Use the same try-catch
block to see how the function coder.mapping.api.get
is now able to retrieve the existing code mappings of the model.
try codeMapObj = coder.mapping.api.get(simulinkModel); fprintf("" + ... " ========================================================\n" + ... " The model already had code mappings.\n" + ... " ========================================================\n"); catch fprintf("" + ... " ==========================================\n" + ... " The model does not have code mappings.\n" + ... " Creating new code mappings for the model.\n" + ... " ==========================================\n"); codeMapObj = coder.mapping.utils.create(simulinkModel); end
======================================================== The model already had code mappings.
Retrieve the storage class of input port inport_1
of the model. Notice that it is the storage class that you set previously.
getInport(codeMapObj,"inport_1","StorageClass")
Close the model without saving it.
close_system(simulinkModel,false)
Input Arguments
Simulink® model for which to create and return a code mappings object, specified as a handle or a character vector or string scalar with the model name (without the.slx
file extension), or the relative or absolute path of the model file (including the .slx
file extension).
Note
The model must be loaded (for example, by usingload_system
).
Example: "configModel"
Data Types: char
| string
| handle
Output Arguments
The model code mappings, returned as a CodeMapping
object or aCodeMappingCPP
object.
Version History
Introduced in R2020b