mustBeFolder
说明
示例
在文件夹中运行
使用 mustBeFolder
函数确保传递给函数的文件夹路径是有效文件夹,并避免使用条件语句来测试函数体中的有效文件夹。
runInFolder
函数确保在更改到指定的文件夹来运行函数之前该文件夹有效。
function r = runInFolder(path) arguments path {mustBeFolder} end orgFolder = cd(path); r = myFunct; cd(orgFolder) end
传递无效的文件夹名称作为输入会导致错误。
r = runInFolder("myFunct.m");
Error using runInFolder r = runInFolder("myFunct.m"); ↑ Invalid argument at position 1. The following folders do not exist: 'myFunct.m'.
输入参数
path
— 文件夹的路径
字符串标量 | 字符向量
文件夹的路径,指定为字符串标量、字符向量、字符串数组或字符向量元胞数组。
示例: "H:\myfolder\mysubfolder"
数据类型: char
| string
提示
mustBeFolder
用于属性和函数参数验证。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
版本历史记录
在 R2020b 中推出
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)