summaryrefslogtreecommitdiff
path: root/modules/string/help/en_US/length.xml
blob: 4b60897ce6166605b2ac732774300206328e18ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) INRIA - 
 * 
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at    
 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xml:id="length" xml:lang="en">
    <refnamediv>
        <refname>length</refname>
        <refpurpose>length of object</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Calling Sequence</title>
        <synopsis>n = length(M)</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>M</term>
                <listitem>
                    <para>
                        a matrix (usual or polynomial or character string) or a
                        list.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>n</term>
                <listitem>
                    <para>an integer or a matrix of integers.</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            For usual or polynomial matrix <varname>n</varname> is the integer
            equal to number of rows times number of columns
            of <varname>M</varname>. (Also valid for <varname>M</varname>
            a boolean matrix).
        </para>
        <para>
            For matrices made of character strings (and in particular for a
            character string) <function>length</function> returns in
            <varname>n</varname> the length of entries of the matrix of
            character strings <varname>M</varname>.
        </para>
        <para>
            The length of a list is the number of elements in the list (also
            given by <function>size</function>).
        </para>
        <para>
            The length of a mlist is by default the number of elements in the
            mlist, but you can overload it (see example). Note that for a non-string
            hypermatrix, there is no need to overload the function. Indeed, <function>length</function>
            returns the product of the dimensions of the hypermatrix.
        </para>
        <para>
            <code>length('123')</code> is <literal>3</literal>.
            <code>length([1,2;3,4])</code> is <literal>4</literal>.
        </para>
        <para>
            <warning>
                WARNING : <function>length</function> of a sparse matrix
                returns the max of dimensions and not the product
                of the dimensions. (For example:
                <code>length(sparse(eye(12,2)))</code>
                returns <code>max(12,2)</code> and not <literal>24</literal>).
                Please use <literal>size(...,'*')</literal> with sparse matrix.
            </warning>
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
length([123 ; 456 ])
length(['hello world',SCI])
length(rand(2,2,2))

    ]]></programlisting>
        <programlisting role="example"><![CDATA[

a = mlist(["myMlistT" "field1" "field2"],"aexample","bexampleb");
length(a)
// returns 3 default behaviour if length not overloaded for mlist

// we create an overload function for mlist of type myMlistT
function r = %myMlistT_length(M)
    r = length(M.field1)
endfunction

length(a)
// returns 8 result of length(a.field1)
    ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See Also</title>
        <simplelist type="inline">
            <member>
                <link linkend="size">size</link>
            </member>
        </simplelist>
    </refsection>
    <refsection>
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>5.4.0</revnumber>
                <revremark>
                    This function allows overloading for mlist type.
                </revremark>
            </revision>
        </revhistory>
    </refsection>
</refentry>