Simulink.fileGenControl
为图更新和模型编译生成的文件指定根文件夹
说明
返回 cfg
= Simulink.fileGenControl('getConfig')Simulink.FileGenConfig
对象的实例的句柄,该对象包含以下文件生成控制参数的当前值:
CacheFolder
- 指定用于仿真的模型编译工件(包括 Simulink® 缓存文件)的根文件夹。CodeGenFolder
- 指定代码生成文件的根文件夹。CodeGenFolderStructure
- 控制代码生成文件夹中的文件夹结构。
要获取或设置参数值,请使用 Simulink.FileGenConfig
对象。
以下 Simulink® 预设项决定 MATLAB® 会话的初始参数值:
Simulink.fileGenControl(
执行使用当前 MATLAB 会话的文件生成控制参数的操作。可使用一个或多个 Action
,Name,Value
)name,value
对组参数指定其他选项。
示例
获取文件生成控制参数值
要获取当前 MATLAB 会话的文件生成控制参数值,请使用 getConfig
。
cfg = Simulink.fileGenControl('getConfig');
myCacheFolder = cfg.CacheFolder;
myCodeGenFolder = cfg.CodeGenFolder;
myCodeGenFolderStructure = cfg.CodeGenFolderStructure;
使用 Simulink.FileGenConfig
对象设置文件生成控制参数
要为当前 MATLAB 会话设置文件生成控制参数值,请使用 setConfig
操作。首先,在 Simulink.FileGenConfig
对象的实例中设置值。然后,传递对象实例。此示例假设您的系统有 aNonDefaultCacheFolder
和 aNonDefaultCodeGenFolder
文件夹。
% 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);
直接设置文件生成控制参数
您可以为当前 MATLAB 会话设置文件生成控制参数值,而无需创建 Simulink.FileGenConfig
对象的实例。此示例假设您的系统有 aNonDefaultCacheFolder
和 aNonDefaultCodeGenFolder
文件夹。
myCacheFolder = fullfile('C:','aNonDefaultCacheFolder'); myCodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder'); Simulink.fileGenControl('set', 'CacheFolder', myCacheFolder, ... 'CodeGenFolder', myCodeGenFolder, ... 'CodeGenFolderStructure', ... Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder);
如果您不想在不同文件夹中为不同目标环境生成代码,请为 'CodeGenFolderStructure'
指定值 Simulink.filegen.CodeGenFolderStructure.ModelSpecific
。
重置文件生成控制参数
您可以将文件生成控制参数重置为 Simulink 预设项中的值。
Simulink.fileGenControl('reset');
创建仿真缓存和代码生成文件夹
要创建文件生成文件夹,请结合使用 set
操作和 'createDir'
选项。通过 'keepPreviousPath'
选项,您可以保留 MATLAB 路径上以前的文件生成文件夹。
% myCacheFolder = fullfile('C:','aNonDefaultCacheFolder'); myCodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder'); Simulink.fileGenControl('set', ... 'CacheFolder',myCacheFolder, ... 'CodeGenFolder',myCodeGenFolder, ... 'keepPreviousPath',true, ... 'createDir',true);
输入参数
Action
— 指定操作
'reset'
| 'set'
| 'setConfig'
指定使用当前 MATLAB 会话的文件生成控制参数的操作:
'reset'
- 将文件生成控制参数重置为 Simulink 预设项中的值。'set'
- 通过直接传递值,为当前 MATLAB 会话设置文件生成控制参数。'setConfig'
- 通过使用Simulink.FileGenConfig
对象的实例,为当前 MATLAB 会话设置文件生成控制参数。
名称-值参数
将可选的参数对组指定为 Name1=Value1,...,NameN=ValueN
,其中 Name
是参数名称,Value
是对应的值。名称-值参数必须出现在其他参数后,但参数对组的顺序无关紧要。
在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name
引起来。
示例: Simulink.fileGenControl(
Action
, Name
, Value
);
config
— 指定 Simulink.FileGenConfig
的实例
对象句柄
指定包含要设置的文件生成控制参数的 Simulink.FileGenConfig
对象实例。
setConfig
的选项。
示例: Simulink.fileGenControl('setConfig', 'config',
cfg
);
CacheFolder
— 指定仿真缓存文件夹
字符向量
为 CacheFolder
参数指定仿真缓存文件夹路径值。
set
的选项。
示例: Simulink.fileGenControl('set', 'CacheFolder',
myCacheFolder
);
CodeGenFolder
— 指定代码生成文件夹
字符向量
为 CodeGenFolder
参数指定代码生成文件夹路径值。您可以指定绝对路径或相对于编译文件夹的路径。例如:
'C:\Work\mymodelsimcache'
和'/mywork/mymodelgencode'
指定绝对路径。'mymodelsimcache'
是相对于当前工作文件夹 (pwd
) 的路径。该软件会在设置CacheFolder
或CodeGenFolder
参数时将相对路径转换为完全限定路径。例如,如果pwd
为'/mywork'
,则结果是'/mywork/mymodelsimcache'
。'../test/mymodelgencode'
是相对于pwd
的路径。如果pwd
为'/mywork'
,则结果是'/test/mymodelgencode'
。
set
的选项。
示例: Simulink.fileGenControl('set', 'CodeGenFolder',
myCodeGenFolder
);
CodeGenFolderStructure
— 指定生成代码的文件夹结构
Simulink.filegen.CodeGenFolderStructure.ModelSpecific
(默认) | Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder
指定生成代码的文件夹内子文件夹的布局:
Simulink.filegen.CodeGenFolderStructure.ModelSpecific
(默认值)- 将生成的代码放在特定于模型的文件夹内的子文件夹中。Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder
- 如果模型是为不同目标环境配置的,请将为各个模型生成的代码分别放在不同的子文件夹中。子文件夹的名称对应于目标环境。
set
的选项。
示例: Simulink.fileGenControl('set', 'CacheFolder',
myCacheFolder
, ... 'CodeGenFolder', myCodeGenFolder
, ... 'CodeGenFolderStructure', ... Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder);
keepPreviousPath
— 保留 MATLAB 路径上以前的文件夹路径
false (默认) | true
指定是否保留 MATLAB 路径上以前的 CacheFolder
和 CodeGenFolder
值:
true
- 保留 MATLAB 路径上以前的文件夹路径值。false
(默认值)- 从 MATLAB 路径中删除以前的旧路径值。
reset
、set
或 setConfig
的选项。
示例: Simulink.fileGenControl('reset', 'keepPreviousPath', true);
createDir
— 为文件生成创建文件夹
false (默认) | true
指定如果文件夹不存在,是否为文件生成创建文件夹:
true
- 为文件生成创建文件夹。false
(默认值)- 不为文件生成创建文件夹。
set
或 setConfig
的选项。
示例: Simulink.fileGenControl('set', 'CacheFolder',
myCacheFolder
, 'CodeGenFolder', myCodeGenFolder
, 'keepPreviousPath', true, 'createDir',true);
避免命名冲突
使用 Simulink.fileGenControl
设置 CacheFolder
和 CodeGenFolder
会将指定文件夹添加到 MATLAB 搜索路径中。此函数的作用与使用 addpath
将文件夹添加到搜索路径相同,可能导致名称冲突。例如,如果您为 CacheFolder
或 CodeGenFolder
指定的文件夹包含与某个打开模型同名的模型文件,则会发生命名冲突。有关详细信息,请参阅什么是 MATLAB 搜索路径?和 MATLAB 可访问的文件和文件夹。
要使用非默认的仿真缓存文件夹或代码生成文件夹位置,请执行以下操作:
删除以下文件夹中可能导致冲突的任何工件:
当前工作文件夹
pwd
。您打算使用的非默认仿真缓存文件夹和代码生成文件夹。
通过使用
Simulink.fileGenControl
或 Simulink 预设项,指定仿真缓存文件夹和代码生成文件夹的非默认位置。
输出参数
cfg
— 文件生成控制参数的当前值
对象句柄
Simulink.FileGenConfig
对象的实例,它包含文件生成控制参数的当前值。
版本历史记录
在 R2010b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)