1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) INRIA -
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
18 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
19 xml:id="length" xml:lang="en">
21 <refname>length</refname>
22 <refpurpose>Number of characters of a text. Number of elements of an array or list.</refpurpose>
26 <synopsis>n = length(M)</synopsis>
29 <title>Arguments</title>
35 a matrix (usual or polynomial or character string) or a
43 <para>an integer or a matrix of integers.</para>
49 <title>Description</title>
51 For usual or polynomial matrix <varname>n</varname> is the integer
52 equal to number of rows times number of columns
53 of <varname>M</varname>. (Also valid for <varname>M</varname>
57 For matrices made of character strings (and in particular for a
58 character string) <function>length</function> returns in
59 <varname>n</varname> the length of entries of the matrix of
60 character strings <varname>M</varname>.
63 The length of a list is the number of elements in the list (also
64 given by <function>size</function>).
67 The length of an array M of cells or of structures is the number of elements of the array.
68 It is equivalent to <literal>size(M, "*")</literal>.
71 The length of a mlist is by default the number of elements in the
72 mlist, but you can overload it (see example). Note that for a non-string
73 hypermatrix, there is no need to overload the function. Indeed, <function>length</function>
74 returns the product of the dimensions of the hypermatrix.
77 <code>length('123')</code> is <literal>3</literal>.
78 <code>length([1,2;3,4])</code> is <literal>4</literal>.
82 WARNING : <function>length</function> of a sparse matrix
83 returns the max of dimensions and not the product
84 of the dimensions. (For example:
85 <code>length(sparse(eye(12,2)))</code>
86 returns <code>max(12,2)</code> and not <literal>24</literal>).
87 Please use <literal>size(...,'*')</literal> with sparse matrix.
92 <title>Examples</title>
93 <programlisting role="example"><![CDATA[
95 length(['hello world',SCI])
99 <programlisting role="example"><![CDATA[
101 a = mlist(["myMlistT" "field1" "field2"],"aexample","bexampleb");
103 // returns 3 default behaviour if length not overloaded for mlist
105 // we create an overload function for mlist of type myMlistT
106 function r = %myMlistT_length(M)
111 // returns 8 result of length(a.field1)
114 <refsection role="see also">
115 <title>See also</title>
116 <simplelist type="inline">
118 <link linkend="size">size</link>
123 <title>History</title>
126 <revnumber>5.4.0</revnumber>
128 This function allows overloading for mlist type.
132 <revnumber>6.0.0</revnumber>
136 The <literal>length()</literal> of any array C of cells was formerly
137 always 3, whatever are the number of dimensions and the sizes of the
138 array. It is now the number of elements of the array at null depth
139 (without recursive counting), equal to <literal>size(C, "*")</literal>.
142 The <literal>length()</literal> of any array S of structures was formerly
143 equal to its number of fields +2, whatever are the number of dimensions
144 and the sizes of the array. It is now the number of elements of the
145 array at null depth, equal to <literal>size(S, "*")</literal>.