MATLAB 帮助中心
验证值是字符串数组、字符向量或字符向量元胞数组
mustBeText(value)
如果 value 不是字符串数组、字符向量或字符向量元胞数组,则 mustBeText(value) 会抛出错误。空的 0×0 字符数组 ''、空字符串 "" 以及缺失字符串均为特殊情况,也记为文本。此函数不返回值。
value
''
""
示例
全部折叠
创建一个数值数组 notText,然后使用 mustBeText 验证值。mustBeText 会抛出错误,因为该数组不包含文本。
notText
mustBeText
notText = [1 2 3]; mustBeText(notText)
Value must be a character vector, string array, or cell array of character vectors.
使用 mustBeText 来限制函数接受的输入参量值。您可以通过向验证输入参量的函数添加参量代码块来实现这一点。
此函数将参量 textInput 的值限制为文本值。
textInput
function MyFunction(textInput) arguments textInput {mustBeText} end end
用数值输入参量调用该函数。MATLAB® 对分配给参量的值调用 mustBeText。mustBeText 会发出错误,因为值 2 不是文本。
2
MyFunction(2)
Error using MyFunction (line 3) MyFunction(2) ^ Invalid argument at position 1. Value must be a character vector, string array, or cell array of character vectors.
要验证的值,指定为标量或数组。如果 value 不是字符串标量或数组、字符数组或字符向量元胞数组,mustBeText 将抛出错误。
示例: mustBeText('foo')
mustBeText('foo')
全部展开
在 R2020b 中推出
mustBeTextScalar | mustBeNonzeroLengthText | arguments
mustBeTextScalar
mustBeNonzeroLengthText
arguments
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 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处