matlab每日练习 lenght函数
水平有限,译文中不妥之处恳请指正
length
Length of vector or largest array dimension
向量长度或数组的最大维数
Syntax
函数原型
numberOfElements = length(array)
Description
函数描叙
numberOfElements = length(array) finds the number of elements along the largest dimension of an array. array is an array of any MATLAB data type and any valid dimensions. numberOfElements is a whole number of the MATLAB double class.
For nonempty arrays, numberOfElements is equivalent to max(size(array)). For empty arrays, numberOfElements is zero.
{(译文)numberOfElements = length(array)获取数组最大的维数.数组可以是任意MATLAB数据类型且具备有效的维数.返回值numberOfElements是一个MATLAB双精度类型的整数.
对于一个非空数组,numberOfElements等于函数max(size(array))返回值.对于空的数组,numberOfElements的值为零.}
Examples.
实例
Create a 1-by-8 array X and use length to find the number of elements in the second (largest) dimension:
创建一个1乘8的数组X,并调用length获取数组的列数目:
X = [5, 3.4, 72, 28/4, 3.61, 17 94 89];
length(X)
ans =
8
| |
Create a 4-dimensional array Y in which the third dimension is the largest. Use length to find the number of elements in that dimension:
Y = rand(2, 5, 17, 13);
length(Y)
ans =
17
| |
Create a struct array S with character and numeric fields of different lengths. Use the structfun function to apply length to each field of S:
S = struct('f1', 'Name:', 'f2', 'Charlie', ...
'f3', 'DOB:', 'f4', 1917)
S =
f1: 'Name:'
f2: 'Charlie'
f3: 'DOB:'
f4: 1917
structfun(@(field)length(field), S)
ans =
5
7
4
1
本文深入解析了Matlab中的length函数,详细解释了其用途、语法、描述,并通过实例展示了如何使用该函数获取数组的维数。包括非空数组和空数组的情况。
3633

被折叠的 条评论
为什么被折叠?



