MATLAB 帮助中心
最大数组维度的长度
L = length(X)
L = length(X) 返回 X 中最大数组维度的长度。对于向量,长度仅仅是元素数量。对于具有更多维度的数据,长度为 max(size(X))。空数组的长度为零。
X
max(size(X))
示例
全部折叠
求出区间 [5,10] 中的均匀分布向量的长度。
[5,10]
v = 5:10
v = 1×6 5 6 7 8 9 10
L = length(v)
L = 6
求出一个由零组成的 3×7 矩阵的长度。
X = zeros(3,7); L = length(X)
L = 7
创建一个字符串数组并计算其长度,即每行中的元素数。
X = ["a" "b" "c"; "d" "e" "f"]
X = 2×3 string "a" "b" "c" "d" "e" "f"
L = 3
创建一个包含 Day 和 Month 对应的字段的结构体。使用 structfun 函数将 length 应用于各个字段。
Day
Month
structfun
length
S = struct('Day',[1 13 14 26],'Month',{{'Jan','Feb', 'Mar'}})
S = struct with fields: Day: [1 13 14 26] Month: {'Jan' 'Feb' 'Mar'}
L = structfun(@(field) length(field),S)
L = 2×1 4 3
输入数组,指定为标量、向量、矩阵或多维数组。
复数支持: 是
要计算字符串或字符向量中的字符数量,请使用 strlength 函数。
strlength
length 不对表执行运算。要检查表的维度,请使用 height、width 或 size 函数。
height
width
size
全部展开
length 函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
backgroundPool
ThreadPool
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
length 函数完全支持 GPU 数组。要在 GPU 上运行该函数,请将输入数据指定为 gpuArray (Parallel Computing Toolbox)。有关详细信息,请参阅在 GPU 上运行 MATLAB 函数 (Parallel Computing Toolbox)。
gpuArray
此函数完全支持分布式数组。有关详细信息,请参阅使用分布式数组运行 MATLAB 函数 (Parallel Computing Toolbox)。
在 R2006a 之前推出
strlength | ndims | numel | size
ndims
numel
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 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处