MATLAB 帮助中心
验证输入路径指向文件夹
mustBeFolder(path)
如果 path 未引用文件夹,则 mustBeFolder(path) 会抛出错误。此函数不返回值。
path
mustBeFolder 调用以下函数来确定输入是否引用文件夹
mustBeFolder
isfolder
支持的类:所有 MATLAB® 类
示例
全部折叠
使用 mustBeFolder 函数确保传递给函数的文件夹路径是有效文件夹,并避免使用条件语句来测试函数体中的有效文件夹。
runInFolder 函数确保在更改到指定的文件夹来运行函数之前该文件夹有效。
runInFolder
function r = runInFolder(path) arguments path {mustBeFolder} end orgFolder = cd(path); r = myFunct; cd(orgFolder) end
传递无效的文件夹名称作为输入会导致错误。
r = runInFolder("myFunct.m");
Error using runInFolder (line 3) r = runInFolder("myFunct.m"); ^^^^^^^^^^^ Invalid argument at position 1. These folders do not exist: 'myFunct.m'.
文件夹的路径,指定为字符串标量、字符向量、字符串数组或字符向量元胞数组。
示例: "H:\myfolder\mysubfolder"
"H:\myfolder\mysubfolder"
数据类型: char | string
char
string
mustBeFolder 用于属性和函数参量验证。
全部展开
在 R2020b 中推出
arguments | mustBeFile
arguments
mustBeFile
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处