Simulink.fileGenControl
Specify root folders for files generated by diagram updates and model builds
Description
returns a handle to an instance of the cfg
= Simulink.fileGenControl('getConfig')Simulink.FileGenConfig
object, which
contains the current values of these file generation control parameters:
CacheFolder
– Specifies the root folder for model build artifacts that are used for simulation, including Simulink® cache files.CodeGenFolder
– Specifies the root folder for code generation files.CodeGenFolderStructure
– Controls the folder structure within the code generation folder.
To get or set the parameter values, use the
Simulink.FileGenConfig
object.
These Simulink preferences determine the initial parameter values for the MATLAB® session:
Simulation cache folder –
CacheFolder
Code generation folder –
CodeGenFolder
Code generation folder structure –
CodeGenFolderStructure
Simulink.fileGenControl(
performs an action that uses the file generation control parameters of the current MATLAB session. Specify additional options with one or more
Action
,Name,Value
)name,value
pair arguments.
Examples
Get File Generation Control Parameter Values
To obtain the file generation control parameter values for the current
MATLAB session, use getConfig
.
cfg = Simulink.fileGenControl('getConfig');
myCacheFolder = cfg.CacheFolder;
myCodeGenFolder = cfg.CodeGenFolder;
myCodeGenFolderStructure = cfg.CodeGenFolderStructure;
Set File Generation Control Parameters by Using Simulink.FileGenConfig
Object
To set the file generation control parameter values for the current
MATLAB session, use the setConfig
action. First, set values in an
instance of the Simulink.FileGenConfig
object. Then, pass the object
instance. This example assumes that your system has aNonDefaultCacheFolder
and aNonDefaultCodeGenFolder
folders.
% Get the current configuration cfg = Simulink.fileGenControl('getConfig'); % Change the parameters to non-default locations % for the cache and code generation folders cfg.CacheFolder = fullfile('C:','aNonDefaultCacheFolder'); cfg.CodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder'); cfg.CodeGenFolderStructure = 'TargetEnvironmentSubfolder'; Simulink.fileGenControl('setConfig', 'config', cfg);
Set File Generation Control Parameters Directly
You can set file generation control parameter values for the current
MATLAB session without creating an instance of the
Simulink.FileGenConfig
object. This example assumes that your system has
aNonDefaultCacheFolder
and aNonDefaultCodeGenFolder
folders.
myCacheFolder = fullfile('C:','aNonDefaultCacheFolder'); myCodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder'); Simulink.fileGenControl('set', 'CacheFolder', myCacheFolder, ... 'CodeGenFolder', myCodeGenFolder, ... 'CodeGenFolderStructure', ... Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder);
If you do not want to generate code for different target environments in separate
folders, for 'CodeGenFolderStructure'
, specify the value
Simulink.filegen.CodeGenFolderStructure.ModelSpecific
.
Reset File Generation Control Parameters
You can reset the file generation control parameters to values from Simulink preferences.
Simulink.fileGenControl('reset');
Create Simulation Cache and Code Generation Folders
To create file generation folders, use the set
action
with the 'createDir'
option. You can keep previous file generation folders
on the MATLAB path through the 'keepPreviousPath'
option.
% myCacheFolder = fullfile('C:','aNonDefaultCacheFolder'); myCodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder'); Simulink.fileGenControl('set', ... 'CacheFolder',myCacheFolder, ... 'CodeGenFolder',myCodeGenFolder, ... 'keepPreviousPath',true, ... 'createDir',true);
Input Arguments
Action
— Specify action
'reset'
| 'set'
| 'setConfig'
Specify an action that uses the file generation control parameters of the current MATLAB session:
'reset'
– Reset file generation control parameters to values from Simulink preferences.'set'
– Set file generation control parameters for the current MATLAB session by directly passing values.'setConfig'
– Set file generation control parameters for the current MATLAB session by using an instance of aSimulink.FileGenConfig
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example:
Simulink.fileGenControl(
Action
,
Name
, Value
);
config
— Specify instance of Simulink.FileGenConfig
object handle
Specify the Simulink.FileGenConfig
object instance containing file
generation control parameters that you want to set.
Option for setConfig
.
Example: Simulink.fileGenControl('setConfig', 'config',
cfg
);
CacheFolder
— Specify simulation cache folder
character vector
Specify a simulation cache folder path value for the CacheFolder
parameter.
Option for set
.
Example: Simulink.fileGenControl('set', 'CacheFolder',
myCacheFolder
);
CodeGenFolder
— Specify code generation folder
character vector
Specify a code generation folder path value for the CodeGenFolder
parameter. You can specify an absolute path or a path relative to build folders. For example:
'C:\Work\mymodelsimcache'
and'/mywork/mymodelgencode'
specify absolute paths.'mymodelsimcache'
is a path relative to the current working folder (pwd
). The software converts a relative path to a fully qualified path at the time theCacheFolder
orCodeGenFolder
parameter is set. For example, ifpwd
is'/mywork'
, the result is'/mywork/mymodelsimcache'
.'../test/mymodelgencode'
is a path relative topwd
. Ifpwd
is'/mywork'
, the result is'/test/mymodelgencode'
.
Option for set
.
Example:
Simulink.fileGenControl('set', 'CodeGenFolder',
myCodeGenFolder
);
CodeGenFolderStructure
— Specify generated code folder structure
Simulink.filegen.CodeGenFolderStructure.ModelSpecific
(default) | Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder
Specify the layout of subfolders within the generated code folder:
Simulink.filegen.CodeGenFolderStructure.ModelSpecific
(default) – Place generated code in subfolders within a model-specific folder.Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder
– If models are configured for different target environments, place generated code for each model in a separate subfolder. The name of the subfolder corresponds to the target environment.
Option for set
.
Example:
Simulink.fileGenControl('set', 'CacheFolder',
myCacheFolder
, ... 'CodeGenFolder',
myCodeGenFolder
, ... 'CodeGenFolderStructure', ...
Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder);
keepPreviousPath
— Keep previous folder paths on MATLAB path
false (default) | true
Specify whether to keep the previous values of CacheFolder
and
CodeGenFolder
on the MATLAB path:
true
– Keep previous folder path values on MATLAB path.false
(default) – Remove previous older path values from MATLAB path.
Option for reset
, set
, or
setConfig
.
Example:
Simulink.fileGenControl('reset', 'keepPreviousPath', true);
createDir
— Create folders for file generation
false (default) | true
Specify whether to create folders for file generation if the folders do not exist:
true
– Create folders for file generation.false
(default) – Do not create folders for file generation.
Option for set
or setConfig
.
Example:
Simulink.fileGenControl('set', 'CacheFolder',
myCacheFolder
, 'CodeGenFolder',
myCodeGenFolder
, 'keepPreviousPath', true,
'createDir',true);
Avoid Naming Conflicts
Using Simulink.fileGenControl
to set CacheFolder
and CodeGenFolder
adds the specified folders to your MATLAB search path. This function has the same potential for introducing a naming
conflict as using addpath
to add folders to the search path. For
example, a naming conflict occurs if the folder that you specify for
CacheFolder
or CodeGenFolder
contains a model file with
the same name as an open model. For more information, see What Is the MATLAB Search Path? and Files and Folders That MATLAB Accesses.
To use a nondefault location for the simulation cache folder or code generation folder:
Delete any potentially conflicting artifacts that exist in:
The current working folder,
pwd
.The nondefault simulation cache and code generation folders that you intend to use.
Specify the nondefault locations for the simulation cache and code generation folders by using
Simulink.fileGenControl
(Simulink Coder) or Simulink preferences.
Output Arguments
cfg
— Current values of file generation control parameters
object handle
Instance of a Simulink.FileGenConfig
object, which contains the
current values of file generation control parameters.
Version History
Introduced in R2010b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)