Main Content

length

最大阵列尺寸的长度

Syntax

Description

example

L = length(X)returns the length of the largest array dimension inX. For vectors, the length is simply the number of elements. For arrays with more dimensions, the length is最大(大小(x)). The length of an empty array is zero.

Examples

collapse all

Find the length of a uniformly spaced vector in the interval[5,10].

v = 5:10
v =1×65 6 7 8 9 10
L = length(v)
L = 6

Find the length of a 3-by-7 matrix of zeros.

X = zeros(3,7); L = length(X)
L = 7

创建一个字符串数组并计算其长度,即每行元素的数量。

X = ["a""b"“C”;“ D”“ e”"f"]
X =2x3 string"a" "b" "c" "d" "e" "f"
L = length(X)
L = 3

Create a structure with fields forDayMonth. Use thestructfunfunction to applylengthto each field.

S = struct('Day',[1 13 14 26],'Month',{{'扬','Feb','Mar'}})
S =struct with fields:Day: [1 13 14 26] Month: {'Jan' 'Feb' 'Mar'}
l = structFun(@(字段)长度(字段),s)
L =2×14 3

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Complex Number Support:Yes

Tips

  • To find the number of characters in a string or character vector, use thestrlengthfunction.

  • lengthdoes not operate on tables. To examine the dimensions of a table, use theheight,width, orsizefunctions.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
使用GPU CODER™为NVIDIA®GPU生成CUDA®代码。

HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

Introduced before R2006a