mustBeText
说明
示例
验证输入为文本
创建一个数值数组 notText
,然后使用 mustBeText
验证值。mustBeText
会引发错误,因为该数组不包含文本。
notText = [1 2 3]; mustBeText(notText)
Value must be a character vector, string array, or cell array of character vectors.
限制参数值
使用 mustBeText
来限制函数接受的输入参数值。您可以通过向验证输入参数的函数添加参数代码块来实现这一点。
此函数将参数 textInput
的值限制为文本值。
function MyFunction(textInput) arguments textInput {mustBeText} end end
用数值输入参数调用该函数。MATLAB® 对分配给参数的值调用 mustBeText
。mustBeText
会发出错误,因为值 2
不是文本。
MyFunction(2)
Error using MyFunction MyFunction(2) ↑ Invalid argument at position 1. Value must be a character vector, string array, or cell array of character vectors.
输入参数
value
— 要验证的值
标量 | 数组
要验证的值,指定为标量或数组。如果 value
不是字符串标量或数组、字符数组或字符向量元胞数组,mustBeText
将引发错误。
示例: mustBeText('foo')
扩展功能
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)