writes real numbers or strings in the console or in a formatted file
write(file_desc, a) write(file_desc, a, format) write(file_desc, a, k, format)
Either
file(…)
(see file).
Using %io(2)
will write in the console.This function can not open a UTF filename. In this case, please uses file.
Matrix of real numbers, or column of character strings.
character string specifying a "Fortran" format. It must begin with
a left parenthesis and end with a right one. The format
must be about only one type of input data. It can't mix placeholders for
real numbers and for strings.
Format examples : "(1x,e10.3,5x,3(f3.0),1x,i4)"
,
"(10x,a20)"
.
"x": | white space. "5x" = 5 white spaces |
"a": | string. "a20" = 20 first characters of the input string. |
"i": | print as integer |
"f": | real number |
"e": | real number in exponential form. |
"(…)": | group. 3(…) = iterate 3 times the group. |
integer vector
writes row-by-row in a formatted file a matrix of real numbers or a column vector
of character strings. If the file already exists, it is overwritten.
Each row of the a
argument
begins a new line of file_desc
file. Depending on
format
, a given row of the a
argument
may be written in more than one line of file_desc
file.
Direct access files :
x=write(file_desc,a,k,format)
. Here
k
is the vector of records (one record by row, i.e.
m=prod(size(k)
)
write(%io(2),....)
writes on Scilab's console.
Note that in this case format
should produce one output
line per matrix row. If this constraint is not verified, unpredictable
behavior could happen.
if getos() == 'Windows' then unix('del asave'); else unix('rm -f asave'); end A = rand(5,3); write('asave',A); A = read('asave',5,3); write(%io(2),A,'('' | '',3(f10.3,'' | ''))') write(%io(2),string(1:10)) write(%io(2),strcat(string(1:10),',')) write(%io(2),1:10,'(10(i2,3x))') if getos() == 'Windows' then unix('del foo'); else unix('rm -f foo'); end write('foo',A) | ![]() | ![]() |
Version | Description |
2023.1 | write(…) overwrites existing file. |