MATLAB 帮助中心
验证值为向量
mustBeVector(value)
如果 value 不是向量,则 mustBeVector(value) 会抛出错误。向量的维度为 1×n 或 n×1。此函数不返回值。mustBeVector 调用 isvector 函数来确定输入是否为向量。
value
mustBeVector
isvector
支持的类:实现 isvector 的所有数值类、logical、char、string 和 MATLAB® 类。
logical
char
string
示例
全部折叠
使用 mustBeVector 验证 a 是行向量或列向量。
a = rand(2); mustBeVector(a)
Value must be a 1-by-n vector or an n-by-1 vector.
mustBeVector 会抛出错误,因为输入是 2×2 数组。
将值 a 重构为行向量。
b = reshape(a,[1,numel(a)]) mustBeVector(b)
mustBeVector 执行时不会抛出错误或返回值。
使用 arguments 代码块通过 mustBeVector 和 mustBeNumeric 将函数输入限制为数值向量。
arguments
mustBeNumeric
WeeklyTotals 函数对输入向量的元素求和。
WeeklyTotals
function r = WeeklyTotals(DailyTotals) arguments DailyTotals {mustBeVector,mustBeNumeric} end r = sum(DailyTotals); end
传递行向量或列向量会返回向量元素之和。
r = WeeklyTotals(1:5)
r = 15
要验证的值,指定为行向量或列向量。如果指定的值不是向量,该函数会抛出错误。
数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | categorical | datetime | duration | calendarDuration 复数支持: 是
single
double
int8
int16
int32
int64
uint8
uint16
uint32
uint64
struct
table
cell
categorical
datetime
duration
calendarDuration
mustBeVector 用于属性和函数参量验证。
全部展开
mustBeVector 函数完全支持 GPU 数组。要在 GPU 上运行该函数,请将输入数据指定为 gpuArray (Parallel Computing Toolbox)。有关详细信息,请参阅在 GPU 上运行 MATLAB 函数 (Parallel Computing Toolbox)。
gpuArray
mustBeVector 函数完全支持分布式数组。有关详细信息,请参阅使用分布式数组运行 MATLAB 函数 (Parallel Computing Toolbox)。
mustBeVector(value,"allow-all-empties")
如果 value 不是向量或空数组,则 mustBeVector(value,"allow-all-empties") 会抛出错误。从 R2026b 开始,不推荐使用此语法。
请改用 mustBeVectorOrEmpty 验证函数验证某个值是向量还是空数组。您可以通过将 mustBeVector(value,"allow-all-empties") 的实例替换为 mustBeVectorOrEmpty(value) 来更新代码。不过目前还没有删除 mustBeVector(value,"allow-all-empties") 语法的计划。
mustBeVectorOrEmpty
mustBeVectorOrEmpty(value)
arguments | isvector | mustBeRow | mustBeColumn | mustBeScalar | mustBeScalarOrEmpty | mustBeVectorOrEmpty | mustBeMatrix
mustBeRow
mustBeColumn
mustBeScalar
mustBeScalarOrEmpty
mustBeMatrix
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 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处