1 <?xml version="1.0" encoding="windows-1251"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2008 - INRIA
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * Copyright (C) 2021 - Samuel GOUGEON
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
19 xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
20 xml:id="mprintf" xml:lang="en">
22 <refname>mprintf</refname>
23 <refpurpose>converts, formats, and writes data to the main scilab window
26 <refnamediv xml:id="printf">
27 <refname>printf</refname>
28 <refpurpose>converts, formats, and writes data to the main scilab window (obsolete)
33 <synopsis>mprintf(format,a1,...,an);</synopsis>
36 <title>Arguments</title>
41 <para>a string providing the format to use to write all next arguments.
42 The <varname>format</varname> follows -- as close as possible -- the C printf
43 format operand syntax, as described in the
44 <link linkend="printf_conversion">printf_conversion</link> page.
45 UTF-8 extended characters and numbered placeholders "%n$.." are supported.
50 <term>a1,...,an</term>
53 Data to be converted and printed according to the <varname>format</varname>
54 argument. Supported types: all numbers, booleans, strings. Only the real part
55 of complex numbers is considered (current Scilab limitation).
62 <title>Description</title>
64 <literal>mprintf(format, a1, a2, ..)</literal> replaces placeholders provided inside the
65 <varname>format</varname> string with values of <varname>a1</varname>, <varname>a2</varname>, ..
66 converted according to each respective placeholder directive, and writes the result to
70 If <varname>a1</varname>, <varname>a2</varname>, .. are arrays with multiple rows,
71 they feed the format row by row: the format is used iteratively for every row of the
72 (horizontally "concatenated") arrays, until the bottom
73 of the least tall array is reached. Remaining rows of taller arrays (if any) are ignored.
77 If the total number of columns of <varname>a1</varname>, <varname>a2</varname>, ..
78 is bigger than the number of placeholders in the <varname>format</varname>,
79 then extra columns are ignored. If it is smaller, an error is yielded.
82 The <literal>mprintf</literal> function is an extended interface for C-coded
83 <literal>printf</literal>.
87 <title>Examples</title>
88 <programlisting role="example"><![CDATA[
90 A = [26.93 ; 63.25 ; 40.51 ; 91.84];
91 B = [ 3.62 ; 15.04 ; 25.3 ; 48.19];
96 Status = ["NOK" "NOK" "NOK" "OK"]';
97 Format = "Iteration %d: Results: A= %f B= %2d%% Status= %3s C(1)= %g C(2)= %e\n";
98 mprintf(Format, I, A, B, Status, C);
101 --> mprintf(Format, I, A, B, Status, C);
102 Iteration 1: Results: A= 26.930000 B= 3% Status= NOK C(1)= 4.37 C(2)= 2.806000e+01
103 Iteration 2: Results: A= 63.250000 B= 15% Status= NOK C(1)= 48.18 C(2)= Inf
104 Iteration 3: Results: A= 40.510000 B= 25% Status= NOK C(1)= 41.48 C(2)= Nan
105 Iteration 4: Results: A= 91.840000 B= 48% Status= OK C(1)= 26.39 C(2)= 7.783000e+01
109 Supernumerary columns or rows are ignored:
111 <programlisting role="example"><![CDATA[
112 A = [%T %F %T %T %F]';
116 mprintf("OK? %s Value: %4.1f\n", A, B);
119 --> mprintf("OK? %s Value: %4.1f\n", A, B);
126 Numbered placeholders "%n$.." allow reordering printed data with the format:
128 <programlisting role="example"><![CDATA[
129 names = ["Peter", "Martha" "John"]';
131 mprintf("%2$6s is %1$d-year old.\n", ages, names);
134 --> mprintf("%2$6s is %1$d-year old.\n", ages, names);
135 Peter is 32-year old.
136 Martha is 25-year old.
140 <refsection role="see also">
141 <title>See also</title>
142 <simplelist type="inline">
144 <link linkend="printf_conversion">printf_conversion</link>
147 <link linkend="disp">disp</link>
150 <link linkend="write">write</link>
153 <link linkend="percentio">percentio</link>
156 <link linkend="percentchars">percentchars</link>
160 <refsection role="history">
161 <title>History</title>
164 <revnumber>6.1.0</revnumber>
166 Numbered placeholders "%n$.." are supported in the format.
170 <revnumber>6.1.1</revnumber>
172 Input data can be boolean.