Group: | Reading and Writing |
See also: | read readm savemac |
Function: | write | |
Description: | write writes an array into a file. |
Usage: | write (x, file {, mode {,fmt}}) | |
Input: | ||
x | multidimensional array | |
file | string with the name of the file | |
mode | string, mode | |
fmt | string, format |
If no format is specified, the ascii-format is used. Use formatstring "x" to save the data in the XploRe-format. Otherwise, the format has to follow the C-conventions.
The following escape sequences produce the associated action on display devices capable of the action:
\n
Newline. Move the printing position to the start of
the next line.
\r
Carriage return. Move the printing position to the
start of the current line.
\t
Horizontal tab. Move the printing position to the next
implementation-defined horizontal tab position on the
current line.
Each conversion specification is introduced by the character
%. After the character %, the following appear in sequence:
Zero or more flags, which modify the meaning of the
conversion specification.
An optional string of decimal digits to specify a
minimum field width. If the converted value has fewer
characters than the field width, it will be padded on
the left (or right, if the left-adjustment flag (-),
described below, has been given) to the field width.
An optional precision that gives the minimum number of
digits to appear
number of digits to appear after the decimal-point
character for the e, E, and f conversions, the maximum
number of significant digits for the g and G conversions.
The precision takes the form of a period (.) followed by a
decimal digit string; a null digit string is treated as
zero. Padding specified by the precision overrides the
padding specified by the field width.
A conversion character (see below) that indicates the
type of conversion to be applied.
If the precision argument is negative, it will be changed to
zero. A negative field width argument is taken as a - flag,
followed by a positive field width.
The flag characters and their meanings are:
-
The result of the conversion will be left-justified
within the field. (It will be right-justified if this
flag is not specified.)
+
The result of a signed conversion will always begin
with a sign (+ or -). (It will begin with a sign only
when a negative value is converted if this flag is not
specified.)
space
If the first character of a signed conversion is not a
sign, a space will be placed before the result. This
means that if the space and + flags both appear, the
space flag will be ignored.
#
The value is to be converted to an alternate form.
For e, E, f, g, and G conver-
sions, the result will always contain a decimal-point
character, even if no digits follow the point (normally, a decimal point appears in the result of these
conversions only if a digit follows it). For g and G
conversions, trailing zeros will not be removed from
the result as they normally are.
0
For e, E, f, g, and G conversions,
leading zeros (following any indication of sign or
base) are used to pad to the field width; no space padding is performed. If the 0 and flags both appear,
the 0 flag will be ignored.
Each conversion character results in fetching zero or more
args. The results are undefined if there are insufficient
args for the format. If the format is exhausted while args
remain, the excess args are ignored.
The conversion characters and their meanings are:
f
The double args is converted to decimal notation in the style [ - ]ddd.ddd, where the
number of digits after the decimal-point
character (see setlocale(3C)) is equal to the
precision specification. If the precision is
omitted from arg, six digits are output; if
the precision is explicitly zero and the #
flag is not specified, no decimal-point character appears. If a decimal-point character
appears, at least 1 digit appears before it.
The value is rounded to the appropriate
number of digits.
e,E
The double args is converted to the style [ -
]d.ddde + dd, where there is one digit before
the decimal-point character (which is non-
zero if the argument is non-zero) and the
number of digits after it is equal to the
precision. When the precision is missing,
six digits are produced; if the precision is
zero and the # flag is not specified, no
decimal-point character appears. The E
conversion character will produce a number
with E instead of e introducing the exponent.
The exponent always contains at least two
digits. The value is rounded to the
appropriate number of digits.
g,G
The double args is printed in style f or e
(or in style E in the case of a G conversion
character), with the precision specifying the
number of significant digits. If the precision is zero, it is taken as one. The style
used depends on the value converted: style e
(or E) will be used only if the exponent
resulting from the conversion is less than -4
or greater than or equal to the precision.
Trailing zeros are removed from the fractional part of the result. A decimal-point
character appears only if it is followed by a
digit.
%
Print a %; no argument is converted.
If the character after the % is not a
valid conversion character, the results of the conversion
are undefined.
If a floating-point value is the internal representation for
infinity, the output is [ + ]Infinity, where Infinity is
either Infinity or Inf, depending on the desired output
string length. Printing of the sign follows the rules
described above.
If a floating-point value is the internal representation for
``not-a-number,'' the output is [+]NaN. Printing of the
sign follows the rules described above.
In no case does a non-existent or small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is simply expanded to contain the conversion result.
write(reshape(1:15,#(3,5)),"my_data.dat","x") read("my_data.dat")
Contents of readVar [1,] 1 4 7 10 13 [2,] 2 5 8 11 14 [3,] 3 6 9 12 15
Group: | Reading and Writing |
See also: | read readm savemac |