mustBeFile
说明
示例
确保输入是有效的文件名
使用 mustBeFile
函数来确保传递给函数的文件路径有效。
readLine
函数确保在访问文件之前文件路径有效。
function r = readLine(path) arguments path {mustBeFile} end fid = fopen(path); r = fgetl(fid); fclose(fid) end
将此文件夹路径传递给 readLine
函数会导致错误。
r = readLine("C:\Users\Public")
Error using readLine r = readLine("C:\Users\Public") ↑ Invalid argument at position 1. The following files do not exist: 'C:\Users\Public'.
输入参数
path
— 文件的路径
字符串标量 | 字符向量
文件的路径,指定为完全限定的文件名,包括包含函数执行上下文中的文件的文件夹。
示例: "H:\myfolder\myfile.txt"
数据类型: char
| string
提示
mustBeFile
用于属性和函数参量验证。
扩展功能
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)